Take a look at the picture below, it’s the output of a regular scaffold command.
As you can see, Rails has automatically pluralized names for views, resource routes, controllers etc, but has not pluralized the model name.
Ever wondered how Rails finds the plural of words while creating controllers, scaffolds, class names etc?
A module in the ActiveSupport class,
ActiveSupport::Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without, and class names to foreign keys.
The default inflections for pluralization, singularization, and uncountable words are kept in
Say you want to make a scaffold Towers;
What if you want the model to remain plural and Rails is going to call it Tower?
rails g scaffold -h we see this option:
Neat! So we can use:
rails g scaffold Towers --force-plural
This will use the plural
Towers, even for the models
We can also edit
inflections.rb file under
ActiveSupport::Inflector.inflections do |inflect|
For more info take a look at the documentation here.