Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails generate wrong pluralize form

I use Ruby 1.9.3 and Rails 3.2.9, when I do the following in a rails console:

1.9.3p125 :003 > "foot".pluralize => "foots" # shouldn't it be "feet"?

1.9.3p125 :004 > "tooth".pluralize => "tooths" # shouldn't it be "teeth"?

1.9.3p125 :009 > "goose".pluralize => "gooses" # shouldn't it be "geese"?

is that a bug in rails pluralize or I did something wrong?

like image 399
user1938765 Avatar asked Dec 26 '22 12:12

user1938765


1 Answers

You can configure the rails inflector. There should be an initializer file in your application to do so: config/initializers/inflections.rb

You can then add a call to "teach" rails the new rule:

ActiveSupport::Inflector.inflections do |inflect|
 inflect.irregular 'tooth', 'teeth'
end

After you restart the server/console the new pluralization should be in place.

like image 89
Yves Senn Avatar answered Jan 13 '23 00:01

Yves Senn