Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 761
gsmendoza Avatar asked Mar 06 '09 06:03

gsmendoza


1 Answers

ActionView::Helpers::TextHelper

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

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

More documentation and examples available here

like image 188
kyku Avatar answered Oct 06 '22 22:10

kyku