Search code examples
ruby-on-railspluralize

How to get accurate pluralization with Rails pluralization


I need very accurate pluralization for my application

I am currently using the Rails built in pluralization method.

I found a problem with the word 'foot'.

When I do:

"foot".pluralize(2)
=> "foots"

The correct pluralization should be feet.

How can I get more accurate results? I have looked for other gems and they all seem to make the same error.


Solution

  • you need to define below code inside your config/initializers/inflections.rb

    ActiveSupport::Inflector.inflections(:en) do |inflect|
      inflect.irregular 'foot', 'feet'
    end
    
    • there are some of plural are not define yet, so you need to define it inside inflections.