Ruby on Rails
WhatGetsPluralized
This page is intended to help sort out when to pluralize names in your Rails application.
Rails follow the rules of common sense in that commands that refer to groups of objects are plural and commands that refer to single objects are singular. It uses the Inflector to infer the singulars from the plurals, as well as CamelCase from under_scored and vice-versa.
Pluralize
- Controller Name – While this doesn’t explicitly need pluralization, if your controller specifically deals with a single model, then it’s good form to pluralize that model for the Controller Name.
- table name – tables house many records to fill many models
- has_many – Because this association will access groups of records
- has_and_belongs_to_many – Once again this associates a group of objects to another group of objects. Can’t get more plural than that.
Singular
- Model Name – A model represents a single record. You should also use the uppercase, singular model name when using the “scripts/generate scaffold” command.
- has_one – This association will only ever return one record
- belongs_to – This will also only return one record.
table name pluralization can be disabled
If you don’t like these rules, you can disable pluralization of table names:
ActiveRecord::Base.pluralize_table_names = false
for more discussion on the matter, see HowtoDisableAutoTableNamePluralisation.
Updated
on July 27, 2008 18:44
by
vshih (76.167.219.100)