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?

Enter The Inflector..

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 inflections.rb.

But what if I don’t want the default pluralizations?

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?

Using rails g scaffold -h we see this option:

1
[--force-plural], [--no-force-plural]

Neat! So we can use:

1
2

rails g scaffold Towers --force-plural

This will use the plural Towers, even for the models

Final thoughts

We can also edit inflections.rb file under config/initializers/inflections.rb

1
2
3
4
5
6

ActiveSupport::Inflector.inflections do |inflect|

inflect.uncountable %w(towers)

end

For more info take a look at the documentation here.