From: Nate Leavitt Date: 2008-07-15T07:43:26+09:00 Subject: Re: array of hashes (finding value) Martin DeMello wrote: > On Mon, Jul 14, 2008 at 2:37 PM, Nate Leavitt > wrote: >>>> >>>> @invoices.each do |invoice| >>>> if invoice[:id] == params[:contact_id] >>>> bla... bla... >>>> end >> >> Thanks for the reply. Yes, I am working in rails :) It just seems >> kinda tedious to keep iterating over all these collections. Just >> wondering if there is a more efficient way. > > Where did @invoices come from in the first place? If it came from the > database, you are probably doing things in your loop that you should > be doing in the sql query (e.g. Invoice.find(params[:contact_id]) > rather than your if guard in the loop) > > martin Yeah... sorry. I actually get the collection through an xml-rpc call :) which returns the array of hashes. -- Posted via http://www.ruby-forum.com/.