Building a Sinatra CRUD Web Application — Manabu List
My project, Manabu List, stems from my passion for online learning. The fact that there are so many courses available to us online (many free of charge) is amazing, but also really overwhelming. Oftentimes, I’m taking a few different courses that are all available on different sites (Coursera, Udacity, etc.), which makes them difficult to track. Manabu List is meant to be an application for people (like me!) who are looking for a way to keep track of all of the online courses they’re currently taking, are interested in taking, or have already completed.
The Programming Process
For our phase 2 project at Flatiron, we were required to:
- Use Sinatra to build the app
- Use ActiveRecord for storing info in a database
- Include user accounts with unique login attributes
- Include has_many and belong_to relationships between models
- Ensure that belongs_to resource has routes for Creating, Reading, Updating, and Destroying
My app’s file structure:
For this project, I used an MVC (Model-View-Controller) file structure. MVC is a popular design pattern that allows for a separation of concerns when developing web applications.
Models —
- course.rb : Within the Course model I declared the belongs_to association to the user model.
- user.rb : The User model declares the has_many association to the Course model. It also holds the username, email, and password validations for when the user signs up. This is where the requirement for unique login attributes for each user can be fulfilled.
Views —
- courses folder : Within my courses view folder are the erb (embedded ruby) files related to the CRUD functionality of the project. The index file within this folder creates the “My Courses” page where the user can see a detailed table of all the courses they’ve added.
- sessions folder : The sessions folder holds all the erb files related to the sessions controller routes, specifically the login page.
- users folder : Within the users view folder is the HTML for the current user’s dashboard where they have all the CRUD functionality available to them on a single page view. The dashboard serves as the main hub from which the user can access the views within the courses view folder.
- layout.erb : The layout file displays the overall HTML structure of my program. As soon as a user creates an account and logs in the navigation bar (coded in this file) will appear on every page.
- error.erb : When a user happens upon a 404 error, this page will be visible to the user; at which point, the user can return to their dashboard.
Controllers —
- application_controller : The application_controller is the class from which every other controller inherits from. This is the controller that gets called for every request. While it is common to define helper methods within the application controller, I chose instead to create a Helpers module that was then included within this controller.
- courses_controller : The courses_controller holds the responses related to creating, reading, updating, and deleting courses. By far, the patch HTTP method took the longest for me to code. I think the added difficulty was in the larger number of attributes (course_name, subject, etc.) that I wanted the user to be able to update.
- sessions_controller : Within the sessions controller, I coded the logic for the user to login and logout of their sessions.
- users_controller : The users controller holds the logic to get and post the signup route, as well as get to the user dashboard.
My repository: Manabu List