Concat results from db query


#1

I’ve got a bunch of records coming back from a database like so

ID WORDS

  1. banana apple orange
  2. apple pear
  3. banana orange

I want to take the records in the WORDS field and concatinate them into
one large array so I can play around with it. How do I do this?


#2

I’m not 100% sure what you’re asking for, but if you have a “Word”
activerecord table with 2 columns(id, words), here is some code that
will
give you what you want.

words = Word.find(:all)
fruits = words.map{|word|word.words}.join(" “).split(” ")


#3

Shane S. wrote:

I’m not 100% sure what you’re asking for, but if you have a “Word”
activerecord table with 2 columns(id, words), here is some code that
will
give you what you want.

words = Word.find(:all)
fruits = words.map{|word|word.words}.join(" “).split(” ")

That worked perfectly Shane, thanks very much.