spike
spike

Reputation: 10004

Rails join a list of strings with commas and "and" before the last

Is there a standard rails helper that converts an array of strings like ["apple", "banana", "pear"] into "apple, banana, and pear" for inserting into a sentence?

Upvotes: 49

Views: 18974

Answers (1)

Webjedi
Webjedi

Reputation: 4737

Yeah to_sentence ought to work nicely.

http://apidock.com/rails/Array/to_sentence

Upvotes: 99

Related Questions