Using RoR pluralization rules


#1

Hello,
RoR seems to be aware of plurals like category=>categories etc…I Want
to
be able to use this in my application to relate some keywords.Is it
possible
?or does RoR itself use some ruby library?
Thanks
Vivek


#2

RoR uses a mixin module for the String class - you can simply call
functions such as pluralize, singularize etc on any string from within a
RoR application.

The module you want to look at is
ActiveSupport::CoreExtensions::String::Inflections.


#3

Marc Croom wrote:

RoR uses a mixin module for the String class - you can simply call
functions such as pluralize, singularize etc on any string from within a
RoR application.

The module you want to look at is
ActiveSupport::CoreExtensions::String::Inflections.

With the caveat that it isn’t always right.


#4

There is a “pluralize” helper you can use to do this. Check out the
Rails
API: api.rubyonrails.org and look for the “pluralize” method in
ActionView::Helpers::TextHelper.

-Will


#5

Look for this in config/environment.rb

Add new inflection rules using the following format

(all these examples are active by default):

Inflector.inflections do |inflect|

inflect.plural /^(ox)$/i, ‘\1en’

inflect.singular /^(ox)en/i, ‘\1’

inflect.irregular ‘person’, ‘people’

inflect.uncountable %w( fish sheep )

end

– -- Tom M.