Rails naming convention for model: community


#1

Hello,

How does Rails deal with the pluralization of community. I have
“community”
as my model name. Will Rails automatically look for a table name
“communities” or do I have to name the table “communitys”?

Thanks.


#2

On 5/21/06, Sam D. removed_email_address@domain.invalid wrote:

Hello,

How does Rails deal with the pluralization of community. I have “community”
as my model name. Will Rails automatically look for a table name
“communities” or do I have to name the table “communitys”?

Rails will look for a table named communities. Rails knows about most
correct English pluralizations. I believe this is a Ruby library.


#3

How does Rails deal with the pluralization of community. I have
“community”
as my model name. Will Rails automatically look for a table name
“communities” or do I have to name the table “communitys”?

“community” will become “communities” when pluralized. You may want
to have a look at the documentation for Rails’ inflector:

http://api.rubyonrails.com/classes/Inflector/Inflections.html

Also, if you’re unsure about how a word will be pluralized/
singularized, try Geoffrey Grosenbach’s Pluralizer:

http://nubyonrails.com/tools/pluralize

– Michael D.


#4

The pluralisations are done with a load of regular expressions in the
inflections.rb file (have a gander:
http://dev.rubyonrails.org/svn/rails/tags/rel_1-1-2/activesupport/lib/active_support/inflections.rb).

You can add others to individual projects by changing environments.rb.
Just look at the commented out bit for an example.

-Nathan