How do I create English-language list (name1, name2, AND name3) in Ruby on Rails?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-05T00:52:45Z Indexed on 2010/05/05 0:58 UTC
Read the original article Hit count: 180

Filed under:
|

Quite possibly there could be a rails magic I've missed, but I'm guessing it will be in Ruby.

I have a model called Company which has_many Contacts.

Suppose Company has Contact 1, Contact 2, Contact 3, and Contact 4.

When I create a textblog for each Contact, I want to output the following (where Contact = Contact 1)

"Hi, Contact 1, I am also writing to Contact 2, Contact 3, and Contact 4."

So it needs to extract the Contact in the salutation and then list them, inserting "and" before the last Contact in the list.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about string