New inflectors in Rails 3.0.5 may break your ActiveRecord models


I decided to write on this in the hope it will help someone else.  I lost too much time on this problem.

I have a Rails application that I migrated from 3.0.3 to 3.0.9.  Suddenly, all my tests were failing on my Media model with this error:

ActiveRecord::StatementInvalid:
Could not find table 'media'

I went in the Rails console, and just typing Media was giving me this error instead of listing the attributes:

=> Media(Table doesn't exist)

What??? I checked my database, everything was fine.  Looks like the pluralization does not work.  And then, I type:

'media'.pluralize
=> "media"

Ha haaaa….. that’s it.  Rails must have new inflectors, and it does!

To fix this, we have two options:

  1. Force the table name in the Model
  2. Add an inflector of our own

I chose the second option since it would apply to my entire app (views as well).  Just had to modify the inflections.rb initializer:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'media', 'medias'
end

There you go. Hope it helps.

2 thoughts on “New inflectors in Rails 3.0.5 may break your ActiveRecord models

Leave a comment