Custom Inflections not working on rails3?

2019-05-05 18:42发布

问题:

I'm using Rails (3.0.1) and have the following code in initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular('nursery', 'nurseries')
end

From the console I'm getting:

"nursery".pluralize => "nurseries"
"nurseries".singularize => "nurseries"

I should be getting:

"nurseries".singularize => "nursery"

Any ideas?

回答1:

I have found a fix!

Place the following code in initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
 inflect.clear :uncountables
 inflect.irregular 'nursery', 'nurseries'
end