Session with Rails and learning React V6

Justin Pitts
3 min readDec 12, 2021

During phase 4 at Flatiron we were introduced to Ruby on Rails. Rails is a great extension that simplifies establishing routes and active record relationships. I found Rails to be a huge time saver compared to using basic Ruby to execute queries from your database. It also takes care of creating relationships between classes for you with a simple one line of code. Now setting up tables in your databases that are related or dependent on others is a breeze. This phase also introduced the MVC (model, view, controller) design using Rails. Basically you set up your routes, the route is sent to the controller that gathers the correct information from the database and sends it back to be viewed.

Rails makes setting up routes so much easier than what we had to do only using rails. You can set up all of the Restful routes just by using the keyword “resources” and telling it which controller it should be sent to. Then you establish your corresponding methods in the controller with what should be executed/returned when it’s called by the route.

For my phase 4 project I decided to create a social media platform for food called “The Food Fix”. User can share all of their favorite restaurants, recipes, bars, cafes, etc. All of the posts shared by users are added to the community board for all other users to see which allows other users to add reviews to them. Each post is assigned to the user that posted it. This gives that user full CRUD authorization for that post. Similarly for reviews, the review belongs to the user that submitted the review and it belongs to the post that it’s reviewing. Only the user who submitted the review can delete it. If a post is deleted by the user who posted it, all the reviews associated with that post are deleted as well.

https://the-food-fix.herokuapp.com/login

My biggest challenge with Rails was setting up the session cookie. For some reason the session wasn’t keeping the user logged in. I looked through all the examples of code I could find and it seemed like I had everything exactly as it should be. However, I would refresh the page and the user was logged out. Honestly I’m not 100% sure how I fixed it. I ended up using the same code that I started with and somehow it started working correctly. I feel like it was some issue with either the Ruby version I was using or having to reinstall react-router-dom and react-router. I was just happy it started working. I probably spent almost 2 days trying to figure it out.

Of course as soon as we started the brainstorming phase for our projects React V6 was release. We basically had to learn all of the updates about the new release on the go while building our projects. This meant looking up the new ways to use params, history and setting up our routes. Luckily our instructor built a sample project and was kind enough to show us how to use a few of the new updates. Still had to use google quite a bit to figure out the use of useNavigation and routes with params.

Overall I found Rails to be a very helpful extension that simplifies a lot of the work for you. Once I got my sessions working correctly the res of the user authentication was no problem. Rails and React are an amazing pair to work with.

--

--