rails2.2.1 snippets

Pluralization with Rails >2.2.1

Tagged pluralization, rails, rails2.2.1  Languages ruby

Rails 2.2.1 moved the Inflector class to the ActiveSupport module, so if you see this error you need to update your code:

"uninitialized constant Inflector (NameError)"

The inflection rules are stored in config/initializers/inflections.rb:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'is', 'are'
  inflect.irregular 'person', 'people'

#   inflect.plural /^(ox)$/i, '\1en'
#   inflect.singular /^(ox)en/i, '\1'
#   inflect.uncountable %w( fish sheep )

Pluralization in views is done like this:

pluralize(@users.size, 'person')
pluralize(@users.size, 'is')


pluralize(@users.size, 'person', 'people')

The documentation can be found at api.rubyonrails.org.