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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s