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.
B15edcdfdbecf5723067df3e24e4f6f0?d=identicon&s=25 Adam Block (adamblock)
on 2007-01-20 20: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


70ca58d0e0e0eabbdb74d177417d09d7?d=identicon&s=25 (Guest)
on 2007-01-20 20: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 Block <>
315035a47dcb93f4427b8a1e18da4ff7?d=identicon&s=25 Jim Lindley (Guest)
on 2007-01-20 21: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, <> wrote:
> On Jan 20, 8:22 pm, Adam Block <>
> > Abby, Bob, and Carol are your friends.
> >
> >
> > --
> > Posted via
> >

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