Forum: Ruby on Rails Conditional pluralize without the number

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Adam B. (Guest)
on 2007-01-20 21:22

Assume you have an array of person names. I want to generate results in
my view that look like this:

Abby is your friend


Abby, Bob, and Carol are your friends.

So I'd like to say:

    <%= friends.to_sentence %>
    <%= pluralize(friends.count, "is") %>
    your <%= pluralize(friends.count, "friend") %>

But because pluralize puts in the number, I get:

Abby 1 is your 1 friend


Abby, Bob, and Carol 3 are your 3 friends.

Is there a way around this? The API only shows the one form for


on 2007-01-20 21:48
(Received via mailing list)
Perhaps this helps:

Kind of strange, though. The Sting::Inflections simply do a
Inflection.pluralize(word), and that method seems to return the word
only (the method I'm talking about is the one in the link above).

On Jan 20, 8:22 pm, Adam B. <removed_email_address@domain.invalid>
Jim L. (Guest)
on 2007-01-20 22:26
(Received via mailing list)
You'll need to use to_sentence to make a custom helper, in

def friends_list_to_sentence(friends)
  if friends.to_a.count == 1
    friends + " is your friend."
    friends.to_sentence + " are your friends."

That's quick and dirty and I didn't test it.

On 1/20/07, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> wrote:
> On Jan 20, 8:22 pm, Adam B. <removed_email_address@domain.invalid>
> > Abby, Bob, and Carol are your friends.
> >
> >
> > --
> > Posted via
> >

Jim L.
This topic is locked and can not be replied to.