method

pluralize

pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
public

Attempts to pluralize the singular word unless count is 1. If plural is supplied, it will use that when count is > 1, otherwise it will use the Inflector to determine the plural form for the given locale, which defaults to I18n.locale

The word will be pluralized using rules defined for the locale (you must define your own inflection rules for languages other than English). See ActiveSupport::Inflector.pluralize

pluralize(1, 'person')
# => 1 person

pluralize(2, 'person')
# => 2 people

pluralize(3, 'person', plural: 'users')
# => 3 users

pluralize(0, 'person')
# => 0 people

pluralize(2, 'Person', locale: :de)
# => 2 Personen

4Notes

Pluralize Without Count

patrickberkeley · Sep 14, 20096 thanks

Helper method that returns the word without the count.

==== application_helper.rb def pluralize_without_count(count, noun, text = nil) if count != 0 count == 1 ? "#{noun}#{text}" : "#{noun.pluralize}#{text}" end end

Example usage:

==== _form.html.erb <%= pluralize_without_count(item.categories.count, 'Category', ':') %>

MUCH easier way to pluralize without the number...

julescopeland · Apr 26, 20125 thanks

Just use Ruby!

"string".pluralize(count)

(Another) Pluralize Without Showing the Count

joshuapinter · Sep 4, 20111 thank

Thought it would be best to take the source code from pluralize and just remove the count from the output.

Create this helper method in application_helper.rb

# Pluralize without showing the count.
def simple_pluralize count, singular, plural=nil
((count == 1 || count =~ /^1(\\.0+)?$/) ? singular : (plural || singular.pluralize))
end

This allows you to pass in in the plural word to use as well.

Pluralize Without Count (inline version)

artemave · Oct 27, 2010

====

= pluralize(item.categories.count, 'Category').sub(/\\d+\\s/, '')