My Rails App
Building my rails app was in many ways a lot harder than I thought it was going to be and in some ways a lot easier than my previous sinatra app. Rails made it so easy to initiate the project through its readability, simplicity and copious easy to use built in methods such as “form_for”, “current_user”, “.build”, “.valid?” and more. Instead of having to code the logic for these methods I could just use these readily available methods that come with rails and active record.
One of the issues I ran into while building my app was that I was trying to piece together my project by watching different tutorials. I was running into a lot of routing issues due to that. Most of them being that a lot of the tutorials were for different kinds of apps so the logic and routing were different. An example of a routing issue I had in my routes file was that I initially kept my users and unicorns routes separate and nested my superpowers routes in the unicorns route. Towards the end of my project when my views and most of my controller methods were completed I decided that I wanted to nest unicorns AND superpowers in my users routes and did not take into consideration that, that I would have to filter through the error messages and change the get_path requests implemented in my views files and controller files. That is because my routes had now changed in order to accommodate the nested routes change in my routes file.
Another issue I struggled with for a while was getting my omniauth google login to work. I decided to utilize the devise gem for this feature and followed a tutorial to learn how to do this and I managed to get everything working up to the point of clicking the account I wanted to choose for logging in. Every time I did that it kept taking me back to the root page instead of logging me in so I debugged it by placing a byebug in the omniath method in my SessionsController and I was perplexed because in the log it stated that it was actually taking me to the route I wanted to go to but was then interrupted by the devise gem and would take me back to the root page. That was because I wasn’t using devise’s login method sign_in_and_redirect user in my sessions controller and it wasn’t hitting my redirect_to … path even though my user.valid? function was returning true. Through this long and arduous debugging process I learned that it can be easy for gems to clash with rail's built-in functions if you’re not careful and the implementation of the gem is not consistent with the instructions given on their site.
Something that I think worked well in my project was adding attributes to my tables. Due to activerecord’s migration capabilities I found it quite easy to do so and I did a lot of adding columns and removing them in order to better adjust my app to the features I wanted to add to it or take away from it. Something I found confusing was figuring out where I should add user_id or unicorn_id or superpower_id. I’m still not sure if I have the right idea of when one should implement an id from a different class but I think it has to do with if that class is nested within another one it should have the id of the class that is its parent.
Overall I had a blast making it and I learned a lot. I also have come to appreciate gems a lot more working on a bigger, more intricate project.
Comments
Post a Comment