Ruby on Rails: Plural vs Singular Cheatsheet

Jerry Huang
3 min readFeb 10, 2020

--

Ruby on Rail is widely known as a framework that can get your web app from 0–60 in a matter of hours. Rails gives developers so many tools and boilermaker templates that developers can solely focus on their writing code rather than configuring their application. All of this comes with a cost:

Convention over Configuration.

Convention over Configuration.

Convention over Configuration.

This was a phrase that was repeated over and over as I learned Rails. To take advantage of all the tools that rails offered, one must follow all the rails convention method of naming.

In general, models are always singular, while databases are almost always plural. Then there are grey areas such as using generators when pluralization is required for some but not other generators.

There were some quick references on the internet but I found myself keeping a spreadsheet on my computer of all the rules for quick reference. Even though I have since memorized most of the rules, it was always best-practice to double-check the rules before creating a generator or proceeding to write code. Undoubtedly, you will experience some instances where your entire application is erroring out because you missed an “s”.

Here is my Cheatsheet for pluralization:

I used Taco Cats as my model. Note that these naming conventions are for the model Taco Cats only. You do not HAVE TO follow these rules but it allows Rails to automate some configurations such as using implicit rendering.

With a multiple word model, we can layout snake case vs camelcase as well.

A lot of many to many model do not have tangible joiner models. Most of the time you can just simply combine the name of the two models for the joiner. An example would be Recipes have many Ingredients. While Ingredients are in many Recipes. There is no clear joiner model so most people will use RecipeIngredients. This is completely fine but caused more complexity in Rails as some files/names are CamelCase (RecipeIngredients) while others are snake_case (Recipe_Ingredients).

Generators

Declarations

File & Directory Names

All file names are snakecase. Only the model files are singular

Routes

*All the controller routes are plural because the controller itself is plural. However, some of the prefixes are singular if you want to use the “_path” shortcuts

These aren’t all the instances of the model naming in a rails app. But it should be enough to get started. Happy coding.

--

--