method
pluralize
v1.1.6 -
Show latest stable
- Class:
ActionView::Helpers::TextHelper
pluralize(count, singular, plural = nil)public
Attempts to pluralize the singular word unless count is 1. See source for pluralization rules.
4Notes
Pluralize Without Count
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...
Just use Ruby!
"string".pluralize(count)
(Another) Pluralize Without Showing the Count
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)
====
= pluralize(item.categories.count, 'Category').sub(/\\d+\\s/, '')