The Amazing Rails Pluralizer

posted Thursday, August 4, 2005 by glyph

→ 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

How to use the pluralizer

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:

  • courses_users
  • courses
  • course
  • courses users
  • CoursesUsers

It is permanently listed at left in the “Tools” menu. The source code will be available soon. Until then, try it out!

Leave a response

Your Comment

Nuby on Rails

Geoffrey Grosenbach / Ruby / Code / Graphics / Design / Rails / Merb / Javascript / CSS

Manufactured with

Subscribe

Subscribe (RSS)