On 12/4/06, Phlip <phlip2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Railsters:
>
> Snack Recipe 10 in Chad Fowler''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)
>
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---