Creating my Sinatra Portfolio Project

William Pannell
2 min readJun 30, 2021

For this project, I decided to build a web application where users can track skateboard parts that they have. The idea came from my personal experience- many times I have held on to old parts (such as the trucks and wheels) to create a new board when the old one snaps, and over time this process results in having an unorganized collection of parts due to the lifespan of each part differing. Having a resource to track the parts would help.

I began by creating a user model in order to cover the login/sign-up features before worrying about the forms that would log the user's parts. Upon creating the user controller, I created the sign-up and login paths. From there, I realized utilizing sessions allowed me to easily track who was currently logged in. The user would sign up, be redirected to the login page, where the session[:user_id] would track the ID of the user logging in. Now creating the association between the parts and the users would be as easy as passing the session[:user_id] into the user_id field of the part while it is being created. In addition, by utilizing an application_controller method that checks whether someone is logged in or not by using the session, I am able to ensure that only logged-in users are able to view/create/edit a user's page. One last error-checking process I created was to make sure that a user signing up was not allowed to have a blank username, blank password, or use a username that already exists within the database. If any of those requirements were not met, whoever is signing up would not be redirected to the login page.

Now that the user elements were set up, I created the parts model. A part belongs to a user, and a user has many parts, and so I created the association by implementing a field for the user_id within the part to track this relationship. With the user flow and relationship between user and part done, it was really just a matter of creating the CRUD of the part. I utilized a drop-down menu for the type of the part, as there are only so many parts of a skateboard, and created a field for the brand name of the board.

The main hurdle within this project was ensuring that the association and session were set up correctly. Without these elements, users would be able to edit other user's page, or a part added would be added to a communally made list of parts between all users instead of individually. However, once I made the connection I could use the session[:user_id] to get the relationship made correctly as well as check for unwanted users, I felt I got the hang of it.

I learned a lot about the general MVC layout, handling user information through sessions, and maintaining the relationship between models with this project.

https://youtu.be/B55A50F5u04

--

--