Hi. Assume you have an array of person names. I want to generate results in my view that look like this: Abby is your friend or 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 or Abby, Bob, and Carol 3 are your 3 friends. Is there a way around this? The API only shows the one form for pluralize. Thanks! /afb -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-20 19:48 UTC
Re: Conditional pluralize without the number
Perhaps this helps: http://api.rubyonrails.org/classes/Inflector.html#M001076 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). Weird. On Jan 20, 8:22 pm, Adam Block <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi. > > Assume you have an array of person names. I want to generate results in > my view that look like this: > > Abby is your friend > > or > > 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 > > or > > Abby, Bob, and Carol 3 are your 3 friends. > > Is there a way around this? The API only shows the one form for > pluralize. > > Thanks! > > /afb > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You''ll need to use to_sentence to make a custom helper, in application_helper.rb: def friends_list_to_sentence(friends) if friends.to_a.count == 1 friends + " is your friend." else friends.to_sentence + " are your friends." end end That''s quick and dirty and I didn''t test it. On 1/20/07, augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Perhaps this helps: > > http://api.rubyonrails.org/classes/Inflector.html#M001076 > > 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). > Weird. > > On Jan 20, 8:22 pm, Adam Block <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Hi. > > > > Assume you have an array of person names. I want to generate results in > > my view that look like this: > > > > Abby is your friend > > > > or > > > > 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 > > > > or > > > > Abby, Bob, and Carol 3 are your 3 friends. > > > > Is there a way around this? The API only shows the one form for > > pluralize. > > > > Thanks! > > > > /afb > > > > -- > > Posted viahttp://www.ruby-forum.com/. > > > > >-- Jim -------------------- Jim Lindley jimlindley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---