Assuming the followings:
- Your Search model have a column “word”
- @top_search is a array with 3 latest search result, where each
element have a :word
- You want to join words from these 3 search objects
Then you just can do as following: @top_search.map(&:word).join(’,’)
Assuming the followings:
- Your Search model have a column “word”
- @top_search is a array with 3 latest search result, where each
element have a :word
- You want to join words from these 3 search objects
Then you just can do as following: @top_search.map(&:word).join(’,’)
You can also do something like Search.find(:all, :select =>
“word”, :limit=>3, :order =>“count desc”) if you only need the word
column from each record and want to be a little easier on memory.
Also, be careful with the Symbol#to_proc shorthand ( map(&:word) )
with large arrays, as it is pretty CPU-inefficient in Rails from what
I understand.