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.

1

2 Answers 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!

Sign up to request clarification or add additional context in comments.

Comments

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.