rubyruby-on-rails-3

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?


Solution

  • Yeah to_sentence ought to work nicely.

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