Forum: Ruby on Rails concat results from db query

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E8b10683c74b1ef33b7fce9916a21290?d=identicon&s=25 Paul Livingstone (Guest)
on 2006-04-11 17:47
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?
0a5d6fa912dda67f9b81017fbd9a81f2?d=identicon&s=25 Shane Sherman (Guest)
on 2006-04-11 22:29
(Received via mailing list)
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(" ")
E8b10683c74b1ef33b7fce9916a21290?d=identicon&s=25 Paul Livingstone (Guest)
on 2006-04-12 09:43
Shane Sherman 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.
This topic is locked and can not be replied to.