Rails creating wrong table name for model

naming-conventions, ruby-on-rails

Solution

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!

Problem

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.

Original source

Related problems