Pergunta

I find today that the word "hero" is pluralized as "heros" instead of "heroes" in the activerecord. I was wondering the following: How a word "knows" how to be pluralized? I know there is activesupport and the inflector, but is there some kind of a lookup vocabulary for the strange pluralizations?

Foi útil?

Solução 2

Yes @JohnDel you are right. For some of the commonly used irregular words its hard coded in this file :

https://github.com/rails/rails/blob/9e0b3fc7cfba43af55377488f991348e2de24515/activesupport/lib/active_support/inflections.rb

See the bottom of the file for irregular words

Outras dicas

Rails does a good job on pluralization most of the time based on the simple grammar of the English language.

When using a word that it does not get right, you can specify the correct forms in the file config/initializers/inflections.rb like this:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural /^(hero)$/i, '\1es'

  inflect.plural /^(ox)$/i, '\1en'
  inflect.singular /^(ox)en/i, '\1'
  inflect.irregular 'person', 'people'
  inflect.uncountable %w( fish sheep )
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top