# Pluralize(count, string) in model (and h?!)

**URL:** <https://www.ruby-forum.com/t/pluralize-count-string-in-model-and-h/78175>\
**Category:** Rails\
**Created:** [December 3, 2006, 4:16pm UTC](https://www.ruby-forum.com/t/pluralize-count-string-in-model-and-h/78175 "2006-12-03T16:16:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [December 3, 2006, 4:16pm UTC](https://www.ruby-forum.com/t/pluralize-count-string-in-model-and-h/78175/1 "2006-12-03T16:16:50Z")

</div>

Railsters:

Snack Recipe 10 in Chad F.'s /Rails Recipes/ sez:

\<%= pluralize @recipes.size, ‘unread recipe’ %\>

I pluralize up in my model. (I generate a lot of HTML there. Sue me!)

I can get to the Aspect Oriented Programming version that Inflector adds  
to  
strings:

```
type = type.pluralize unless count == 1
return count.to_s + ' ' + type

```

I want to dry that up; one line for two. But one line…

```
Inflector.pluralize count, (' ' + type).pluralize

```

…gives:

```
ArgumentError: wrong number of arguments (2 for 1)

```

Why am I asking about such a trivial method?? Because, while we are on  
the  
topic, I also want to abuse^W exploit h() in my models, and those  
naughty  
single-letter methods are super-hard to Google for!

–  
Phlip  
[http://www.greencheese.us/ZeekLand](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [December 4, 2006, 12:03am UTC](https://www.ruby-forum.com/t/pluralize-count-string-in-model-and-h/78175/2 "2006-12-04T00:03:44Z")

</div>

On 12/4/06, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> strings:  
> ArgumentError: wrong number of arguments (2 for 1)

That would be because the pluralize() method as implemented in  
ActionView::Helpers::TextHelper adds a bunch of stuff:

# File vendor/rails/actionpack/lib/action\_view/helpers/text\_helper.rb,

line 62  
62: def pluralize(count, singular, plural = nil)  
63: "#{count} " + if count == 1  
64: singular  
65: elsif plural  
66: plural  
67: elsif Object.const\_defined?(“Inflector”)  
68: Inflector.pluralize(singular)  
69: else  
70: singular + “s”  
71: end  
72: end

If you have already made the decision to generate html in your model  
classes, it may not be such a stretch to include TextHelper in your  
model classes as well, even though that is a bit ugly…

Don’t know where the h() method is implemented though.

Cheers,  
Max
