method
pluralize
v1.1.6 -
Show latest stable
-
5 notes -
Class: ActionView::Helpers::TextHelper
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (38)
- 2.0.3 (13)
- 2.1.0 (-14)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-3)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-2)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (35)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (2)
- 7.1.3.4 (0)
- What's this?
pluralize(count, singular, plural = nil)
public
Attempts to pluralize the singular word unless count is 1. See source for pluralization rules.
Register or
log in
to add new notes.
patrickberkeley -
September 14, 2009
6 thanks
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', ':') %>
julescopeland -
April 26, 2012
5 thanks
joshuapinter -
September 5, 2011
1 thank
(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.
artemave -
October 27, 2010
0 thanks
Pluralize Without Count (inline version)
= pluralize(item.categories.count, ‘Category’).sub(/d+s/, ”)
singsai -
January 8, 2013 - (v3.0.0 - v3.2.8)
0 thanks
Minor edit of pluralize_without_count
patrickberkeley’s method works great. I corrected the grammar a bit for inflection (the singular error).
application_helper.rb
def pluralize_without_count(count, noun, text = nil) if count != 0 count == 1 ? "an #{noun}#{text}" : "#{noun.pluralize}#{text}" end end
This should work in much older versions of Rails also.