Singular or Plural? A Cheatsheet for Ruby on Rails Generators
Shannon Crabill

Shannon Crabill @scrabill

About: Front-End Software Engineer

Location:
Baltimore, MD
Joined:
Apr 6, 2017

Singular or Plural? A Cheatsheet for Ruby on Rails Generators

Publish Date: Feb 14 '20
59 6

Ruby on Rails (Rails) is good at doing the manual work for you. With one line, Rails can create the model, controller and view files associated with your application. The downside of using rails generate or its shortcut rails g is that small mistakes like typos are amplified. If Rails is expecting user, and you mistakenly typed users it could cause functionality errors.

This cheat sheet will help to avoid those conflicts.

If you are comfortable working with Rails, Model–view–controller (MVC) architecture rails generate, this post is for you.

Noun Singular? Plural? Example
Controller No Yes users_controller.rb, products_controller.rb
Migrations / Tables No Yes 001_create_users.rb, 002_create_products.rb
Model Yes No user.rb, product.rb
Routes No Yes :users, :products
Seed Data No Yes seeds.rb
Scaffold Yes No rails g scaffold user
View No Yes /users, /products

Resources

Update

The above chart was updated on February 15th 2020 to include scaffolds. Thank you timnans for the suggestion! The table was also put into alphabetical order by noun.

The post Singular or Plural? A Cheatsheet for Ruby on Rails Generators appeared first on Shannon Crabill — Software Engineer && Email Developer.

Comments 6 total

  • Salman Sohail
    Salman SohailFeb 14, 2020

    Nice work !

  • timnans
    timnansFeb 14, 2020

    You could also add the 'scaffold' to the cheetsheet

    • Shannon Crabill
      Shannon CrabillFeb 15, 2020

      This is a good idea! The chart has been updated to include scaffold!

  • Andrew Brown 🇨🇦
    Andrew Brown 🇨🇦Feb 14, 2020

    This is information I cannot remove from my memory.

  • Oliver
    OliverFeb 15, 2020

    It's join table naming that always trips me up.

  • Ben Koshy
    Ben KoshyDec 14, 2020

    excellent! thank you!

    (This is worthy of a PR to the rails documentation itself!?)

Add comment