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.

http://blog.hasmanythrough.com/2006/3/7/symbol-to-proc-shorthand
(check the comments)

Jarin Udom
Robot Mode LLC

On Feb 15, 10:21 pm, Samiron <samironp...@gmail.com> wrote:
> 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(',')
>
> Hope it will work if my assumptions are correct :)
>
> On Feb 16, 12:01 pm, Greg Ma <li...@ruby-forum.com> wrote:
>
>
>
> > Hello,
> > Is it possible to make a "join" on an array of objects?
> > If not, is is possible to return only one column with the find method?
>
> > #method
> >   def self.top_3_words
> >     Search.find(:all,:limit=>3, :order =>"count desc")
> >   end
>
> > #View
> > <% if !...@top_search.blank? %>
> >   <%= @top_search.word.join(",") %> ?????????????????
> > <% else %>
> >  <p>No search yet!</p>
> > <% end %>
>
> > Greg
> > --
> > Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to