2

I'm creating a model named Stadium with rails g model Stadium but rails is converting table name to stadia.

I've manually changed table name to stadium in the migration, and added set_table_name "stadium" in my model class. But all my routes are looking for stadia_path.

I've tried rails g model Stadium --force-plural with no success.

I think I should use an inflection for this, but I don't know how to create this inflection. Stadium is singular, I still need the plural stadiums for this model.

4

2 回答 2

11

The dictionary says that both "stadiums" and "stadia" are correct (given that the word is Latin, "stadia" as plural for neuter words ending in -um seems legitimate).

Just add this to config/initializers/inflections.rb:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'stadium', 'stadiums'
end

You can set up all kinds of irregular plurals here.

Destroy your old generation by doing

rails d model Stadium

and generate it again doing

rails g model Stadium

You will see how it magically creates files like this:

db/migrate/20130330130335_create_stadiums.rb

Then run the migration and you're set!

于 2013-03-30T13:04:08.513 回答
2

For inflections you have to something like this in the config/initializers/inflections.rb:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'stadium', 'stadiums'
end

hope it helps!

于 2013-03-30T12:59:24.137 回答