From: Jacob Basham Date: 2007-11-13T06:27:43+09:00 Subject: Re: newbie stuck with multiple conditions Martin, Your "variation" is doing the same as what you had before in your first email. Also creating variables with your parameters is not necessary, pointless really. And yes, what I put was a bit off, as I said I was on the bus. I believe you can go @listings = ListingDetail.find(:all, :conditions => {:garage_id => params[:garage][:id], :room_id => params[:room][:id], :suburb_id => params[:suburb][:id] } What this is doing is creating a Hash of their key/value pairs, and passing that Hash as the conditions for the find query. If you look at the console window you are running the rails server in, you should see something like SELECT * FROM ListingDetails WHERE garage_id = x AND room_id = y AND suburb_id = z Now, you need to be careful because you will get into some tricky business if either of your three id's are not passed in your search. That should give you enough to get running ,but like I said before this is really something that should be discussed on the rails mailing list. Good Luck, Jake On Nov 11, 2007, at 10:37 PM, Martin Robertson wrote: > Hi Jacob > > I have tried what you have suggested > > @listings = ListingDetail.find(:all, :conditions => ["suburb_id = ? > AND > bedroom_id = ? AND garage_id = ?", params[:suburb_id], params > [:bedroom_id], params[:garage_id]]) > > but it throws up errors as > > app/controllers/admin/listing_details_controller.rb:55: syntax error, > unexpected tLBRACK, expecting ']' > [:bedroom_id], params[:garage_id]]) > ^ > app/controllers/admin/listing_details_controller.rb:55: syntax error, > unexpected ',', expecting kEND > [:bedroom_id], params[:garage_id]]) > ^ > app/controllers/admin/listing_details_controller.rb:55: syntax error, > unexpected ']', expecting kEND > [:bedroom_id], params[:garage_id]]) > ^ > app/controllers/admin/listing_details_controller.rb:85: syntax error, > unexpected $end, expecting kEND > > I have also tried a variation of this > > def results > > suburb_id=params[:suburb][:id] > bedroom_id=params[:bedroom][:id] > garage_id=params[:garage][:id] > @listings=ListingDetail.find( > :all, > :conditions =>["suburb_id =:suburb_id and bedroom_id=:bedroom_id and > garage_id=:garage_id", > { > :suburb_id =>suburb_id, > :bedroom_id=>bedroom_id, > :garage_id=>garage_id > } > ] > ) > end > > this produces error message > > Showing app/views/admin/listing_details/results.rhtml where line #2 > raised: > > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > > Extracted source (around line #2): > > 1: > > > RAILS_ROOT: ./script/../config/.. > > (--deleted all this stuff--) > > Request > Parameters: {"garage"=>{"id"=>"1"}, "commit"=>"Search", > "suburb"=>{"id"=>"2"}, "bedroom"=>{"id"=>"1"}} > > I have also posted this as new post in correct rails forum as advised > > Martin > -- > Posted via http://www.ruby-forum.com/. >