→ Go straight to the pluralizer!
One of the features of Rails that confuses people learning the framework is the automatic pluralization of Model and table names.
Because Rails emphasizes convention over configuration, it’s important that you use the right terms. The Rails generators do not enforce these configurations, so you must learn and follow them. For example, the convention is to use singular model names, but the generator will let you use a plural. Don’t do it! Use the singular for your model names.
./script/generate model Post
Fortunately, Nuby on Rails comes to the rescue with the Amazing Rails Pluralizer!
You enter one or more words, and the pluralizer will use the Inflector module to show you what Rails will do with that word.
Here are the basics:
| Model Name | Singular. Camel-cased. No suffix. Example: Post or CoursesUser |
| Table Name | Plural. All lowercase. Underscores used to join names of multiple tables for has_and_belongs_to_many relationships. Example: courses_users |
| Presentation | When you use scaffolding, column names are sentence-cased and underscores are replaced by whitespace. Example: Created at |
You can type any variation and see what the Inflector does with it. You can then use this information to make sure your code is referring to the correct names. The Inflector code is pretty simple and it might not always pluralize in the way you expect. If necessary, submit a bug report!
Examples of words you can type into the Inflector:
It is permanently listed at left in the “Tools” menu. The source code will be available soon. Until then, try it out!