Flatiron’s Rails Portfolio Project
It feels like this is the middle of the road for the web development track through Flatiron School. For this project I built a Ruby on Rails application that manages related data through complex forms and RESTful routes. It puts to practice using forms and also uses the CRUD verbs and actions which were learned in the Sinatra Section.
The object of this project is to create a simple Content Management System. I chose to create Baby Steps, which is a way to keep track of the skills a baby has learned, allows comments to be saved for each skill learned.
In order to keep the application simple, and meet the criteria a total of 4 tables were created. A users, children, skills and accomplishments.
One of the first things I did was to draw out the schema for the application. Here is where I checked that the main associations would be created and thought about the minimum attributes needed to make the application functional.
Creating my own authentication system
Through the Rails section at Flatiron there were certain gems which we learned about as well as what the ‘Rails Magic’ that the command rails scaffold can do. The gems Cancan, Pundit, and Devise can potentially be great gems when the application requires several roles, authorizations and access. I did not use any of these gems because they are more than what the current application that I am creating needs and I wanted to go over how to create my own authentication system. This suggestion was also given by one of the instructors at Flatiron. The instructor mentioned that we may or may not encounter jobs or applications that use those gems but we would be asked to work with an authentication system and knowing the basics of where to look could be beneficial.
Even though it would have probably decreased the amount of total time I spend on this application I chose not to use the scaffold command. I did use the scaffolds.scss file and referenced the code blocks using the methods errors.full_messages to display the errors on the forms, if they occurred.
The more I started to work on this project the more I was referencing blog posts, stack overload, Rails documentation and previous labs. A lot of the time that I originally thought I would be ‘coding’ I was actually spending it reading.
Attending the study groups has provided a lot of great resources and one of the ones which helped me a lot with authentication, to understand most of it and get the code to work was by Robert SJ ‘Building authentication from scratch in using Ruby on Rails.
Once I got the basics of the application working I went back and added the OmniAtuth Gem so I can use a third party logging in system, in this case Facebook. As previously mentioned researching and reading was almost one of the first things I did when I went to work on a feature of the project. The blog post by E.Choi gave an example of what the user model needed to look like. In this blog post the Figaro gem was used which manages the keys that are used to log in the user.
In my project I explained in the Readme how you can export the keys onto the terminal to do a similar thing. These keys are to not be commited, or shared since it works a bit like your username and password. We would not want to distribute those publicly.
Once the nested form was created, which is submitting a child when the user is created and the second one when a comment can be submitted while updating the skills. In order for the nested forms to work one of the things that needs to at the top of the model.
Even when I added the `accepts_nested_attributes_for` I was still getting an error, and the attributes were not getting updated correctly and at other times there was a duplicate submission. A type of custom validation was created to reject the attributes. This was to decide if the application was to create or not a record.
The app is pretty simple, without a lot of features nor styling, but it meets the requirements listed for the project. Throughout the project I read and researched a lot more than I originally expected. This was to either look up a method that was reviewed in a lesson or to see if there was a method that did a desired action. It then led to further reading of exampled and through the Rails Guides to see how the code was put together.