After months of learning about Ruby, HTTP requests, Active Record, and more, I finally arrived to the Ruby on Rails portion at Flatiron School a few weeks ago. What an adventure it has been. All that hard work and now I am learning about all the magic this framework has to offer (not to mention the abundance of resources across the web). I know there are haters out there who say it is dying/dead, but it has so much to offer in so many different areas. I feel like the more I follow the Rails path, the better I get at creating software not just programming.
We were tasked with creating a simple CRUD web application with a solid back-end. Very similar to our Sinatra project with a few more requirements and a lot more magic (I still can't get over the magical built-in helpers of this framework). I decided to build a project/issue tracker where users can create projects, submit issues, and assign tasks to themeselves. Fix And Forge was born. I know... I have this cliche affinity for alliteration.
Creating a new Rails application is as easy as:
rails new application-name
And once you're in your new application's root directory you can generate just about whatever you want with:
rails g resource rails g migration rails g model
These commands take a number of arguments and options and inform you what was done. It is awesome and I can't get over all the work devs have put into making Rails development so smooth, consistent, and even fun.
As I was working on my models, controllers, views, partials, and helpers I ran into a number of gotcha's. Here are a few of them:
- In a belongs_to migration put user_id not just user
- Make sure to include local: true in your list of arguments to form_with
- A form within a nested route needs to have the url: path specified
- If you want to take advantage of your has_many through relationships make sure you also have the has_many relationship with the model you are going through.