Off The Rails
We’ve passed the point of no return! If you would have told me in February that by the summer I would be able to build a fully functioning app, I would’ve been on the ground in a fit of laughter. Phase 3 — Rails, marks the crossing of the halfway point in the part time curriculum. At this point, I have created a CLI app and an app utilizing Sinatra. For this project, we are using Rails! I was very excited to learn Rails because I had heard about “Rails magic” and how it makes programming easier with its method’s that create html code, descriptive error messages and much more.
My first objective was trying to figure out what kind of app to create. Sometimes this is the toughest decision and longest to figure out. I thought of my pre-pandemic life and how I would travel often to visit clients or visit the factory in Italy where our clothing was manufactured (I worked in the fashion industry). I would travel to all of these great cities and forget either where I ate or what I ate, but usually had great culinary experiences. I sometimes took a photo of the location or wrote it in my Iphone notes app, but usually deleted, forgot or lost them. I decided to create an app that would keep all of my culinary experiences in one place, easy to use and easy to access. I would also allow other users to see my entries and vice versa and search by location so that if I went to visit Florence again, I could revisit my restaurants, but also try others that were recommend by other users.
Having read the requirements, I knew that this project was going to much more labor intensive and I needed a plan before I started working on the project, so I created a flow chart. I began with my models and the relationships between each model. I would have a User, Restaurant, Location models, with a Meal model as a join table between Users and Restaurants.
This would help set the stage for everything. My routes, nested routes, controllers, views etc.
The next challenge was to begin this process and put my ideas to code and here was where the Rails magic began! I was able to use the Rails generator called resource, to create my model, controller, view folder, routes, helper files and more in one quick command. This saved me a ton of time and helped create the skeleton for my app.
From there, I created my routes for login, signup, and selected my nested route to be restaurants/meals.
After that, I created the functionality of my app which included being able to create a user account, then being brought to a user dashboard with all of the users restaurants. The user can then create a new restaurant or click an existing. If they click an existing restaurant, they receive the name, location and meals associated with that restaurant. The user can then add a new meal or click and existing meal. If they click the existing meal, they can see the name and description of that meal and only the user who created the meal can edit or delete the meal submission.
As I went through this project, I had a ton of ups and downs. At times, I thought it was too much to handle, but I also learned a lot of really amazing lessons. I continued the art of Googling to find new answers, I learned how to create partials, helpers and scope methods. I also learned how to create and Omniauth signin option using Github.
The code essentially is saying that we want to find or create a user by its provider (Github) and a unique id. If all of the necessary information is valid (email, first name, password), we want the session[:user_id] to equal the user.id and login them into the app.
I am still in the process on working on the front end to make it a little cleaner and easier on the eyes, but I’ve hit all of my requirements for this project. It was very challenging, but I also learned how important it is to make mistakes, learn and try again. I came from a very fast paced industry that wants immediate results, but I am learning the importance of patience, practice and did I mention….patience?