I have a search form that takes user input, and displays the results in a search_results.rhtml view. In my controller for the search form, I have the following declarations and am using the call to "find":
beds = params[:beds] baths = params[:baths] sqft = params[:sqft] neighborhood_id3 = params[:neighborhood_id3] neighborhood_id4 = params[:neighborhood_id4] neighborhood_id6 = params[:neighborhood_id6]
@properties = Property.find(:all, :conditions => ["AREA like ? OR AREA like ? OR AREA like ? AND NO_BEDROOMS >= ? AND NO_FULL_BATHS >= ? AND SQUARE_FEET >= ?", neighborhood_id3, neighborhood_id4, neighborhood_id6, beds, baths, sqft])
Then I display all the properties returned in the search_results.rhtml view.
The neighborhood part is working. These are checkboxes on the search form, and if you check neighborhood_id3, you get only that neighborhood returned in the result. However, the beds, baths, and sqft, are not working. The entries that are returned are not within what the user selected, ie: only show properties with beds > 2 does not work.
Can anyone see what the problem is in my find statement? In my sql database, I changed the types to varchars, thinking that they had to be strings to do the comparison. Not sure if that is true, but it didn't help me in any case.
Maybe someone could suggest a more elegant implementation as well ... this does seem a little brute force?
Thanks in advance! LAB