ruby-on-railsrubyinflector

Pluralize "part of speech"


I want to generate a model called "part of speech". The natural plural to that would be "parts of speech". I can force that with ActiveSupport::Inflector, but as far as I can tell, I'd need to do that for "parts_of_speech" and "PartsOfSpeech" to cover all three cases.

This feels a little dirty. Am I approaching this right? Is there a better way?


Solution

  • You can do that. Just create a file config/initializers/inflections.rb and add the following to it:

    ActiveSupport::Inflector.inflections do |inflect|
      inflect.irregular 'part_of_speech', 'parts_of_speech'
    end
    

    Read more about the Inflector: http://api.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html