gsmendoza
gsmendoza

Reputation: 1394

Is there a helper method for pluralization in Rails?

def plural(value, string)
  "#{value} #{value.abs == 1 ? string.singularize : string.pluralize}"
end

If not, what would be a short, sweet name for this method?

Upvotes: 14

Views: 4291

Answers (1)

kyku
kyku

Reputation: 6052

ActionView::Helpers::TextHelper

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

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

More documentation and examples available here

Upvotes: 22

Related Questions