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?
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
Yes @JohnDel you are right. For some of the commonly used irregular words its hard coded in this file :
See the bottom of the file for irregular words
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.