Wrap text
|
|
def self.search(options={})
# params and their defaults
# category=1, low_price=100,000, high_price=300,000, bed=3, bath=2, sq_ft=nil, city=user.city, state=user.state, zip=user.state
#condition_string = ""
conditions = []
values = []
options.symbolize_keys!.reject! {|k,v| v.blank? }
# category = options[:category].nil? ? "category=1" : "category=" + options[:category].to_s
# condition_string << category
category = options.delete(:category) || 1
conditions << "category = ?"
values << category
# condition_string << " AND bedroom >= " + options[:bedroom].to_s unless options[:bedroom].nil?
# condition_string << " AND bathroom >= " + options[:bathroom].to_s unless options[:bathroom].nil?
# condition_string << " AND square_feet >= " + options[:square_feet].to_s unless options[:square_feet].nil?
#
# condition_string << " AND locations.city=" + options[:city].to_s unless options[:city].nil?
# condition_string << " AND locations.state=" + options[:state].to_s unless options[:state].nil?
# condition_string << " AND location.zip=" + options[:zip].to_s unless options[:zip].nil?
options.each do |key,value|
case key
when :bedroom
conditions << "bedroom >= ?"
values << value
when :bathroom
conditions << "bathroom >= ?"
values << value
# ... and so forth
end
end
conditions = conditions.join(" AND ")
conditions = [conditions, values].flatten
# unless condition_string.empty?
# listings = Listing.find(:all, :conditions => condition_string, :include => :location)
# else
# listings = Listing.find(:all)
# end
find(:all, :conditions => conditions, :include => :location)
end
|