From: Jacob Basham Date: 2007-11-12T12:11:07+09:00 Subject: Re: newbie stuck with multiple conditions 1. You should be posting to the rails list, not the ruby list. 2. Conditions takes an array OR a dictionary. I believe what you are trying to do is the following: @listings = ListingDetail.find(:all, :conditions = ["suburb_id = ? AND bedroom_id = ? AND garage_id = ?", params[:suburb_id], params [:bedroom_id], params[:garage_id]]) 3. There is a logic error in your second case, calling type_find_by_other_id, you need to pass an actual id. :all means find all. If you want to find all, its just find(:all). And for your object model, I'm thinking a listing should have a int number rooms and either int number car garage, or bool if has garage. Sorry if this isn't more informative, but I'm on the bus and its bumpy. Jake Sent from my iPhone On Nov 11, 2007, at 6:47 PM, Martin Robertson wrote: > Hi > > I am new to rails and programming. > > I am trying to get a conditional search from form results for a > property > search. > > I want to be able to contruct a search that will search (:all) if ID > for > all is returned or by individual ID > > The code below does not work for the all condition > > 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 > > I have also tried use case and if as below > > def results > > bedroom_id=params[:bedroom][:id] > case bedroom_id > when 6 > @listings=ListingDetail.find_all_by_bedroom_id(:all) > else > @listings=ListingDetail.find_all_by_bedroom_id(bedroom_id) > end > garage_id=params[:garage][:id] > case garage_id > when 4 > @listings=ListingDetail.find_all_by_garage_id(:all) > else > @listings=ListingDetail.find_all_by_garage_id(garage_id) > end > > end > > Any help would be appreciated > > Martin > -- > Posted via http://www.ruby-forum.com/. >