Sneakers & Sinatra
When coming across my second portfolio project I had ideas on what i’d like to create. I then thought about one of my passions. Which happened to be sneakers. Then I thought about an application that was already created which is StockX. I only took one part of the idea and wanted to create a sneaker portfolio for users who have sneakers.
So with that idea, I had fun creating and reminiscing all the sneakers i’ve own and all the ones that my friends have own the crazy stuff too. So with the help of the amazing person behind Corneal, I generated Sinatra app, but in a rails like fashion.
This is what the user would see the welcome.erb page which asks them if they would like to login, sign up or check out all the sneakers thats been added into the system. With all the links i’ve had set up the sign up was done through the application controller.
When having the user sign up for my program, I have their password secured and name under uniqueness within the user model. I also have their input nested within the name user. Once done, the user gets prompted to a big page where they can create their sneakers, update and delete them within their profile!
But first the login and having the current session take in the user who was just signed into the program. My post method for login has a variable named user set to find a user by their name and then had it set to a condition if the user and password match the what the database holds; it’ll hold a session with that user and redirect them to their personal profile. But if they seem to make a mistake I had the post login set to direct the user to an error page that asks them to try again to login to their account.
Once the user has logged in, I had to make sure that there was a bunch of forms for the user to be able to create, delete and update their sneakers as well as them having their portfolio of shoes that they’ve made. I nested the sneaker input with the key of sneaker and had them set to a user id so whenever a shoe is called upon it only shows up for that particular user. When it came editing and deleting, both were somewhat similar, but with the editing it was set to bring the user to a different web page to edit their sneakers. While the delete feature is done on the spot and then takes the user to the sneakers index where it shows all the sneakers that were created.
When sending the user to the edit erb within the sneakers folder, they’ll see the sneaker they chose to edit and an option to edit their sneaker, i’ve tried to make it as simplistic as possible. The form that was created had the action sent to a patch within the application controller that reads the id of the sneaker that was put in and then has it updated; if it happens to fail it will send the user back to the edit page.
For deleting someone’s sneaker, it was quite simple actually, instead of bringing the user to a different page, we had it done within the same page and update immediately. We take the user’s sneaker and post them to the delete method thats in the application controller which finds the sneaker and then destroys it, that’s it!
The user has the option to log out anytime, within their profile, we set a get route to have the session cleared and redirect the page to the welcome erb where the user has the option to log in again.
It’s a very simplistic app but I enjoyed making it, thank you for the read and have a fantastic day!