# Need help with a search logic problem

**URL:** <https://www.ruby-forum.com/t/need-help-with-a-search-logic-problem/123460>\
**Category:** Rails\
**Created:** [December 17, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/need-help-with-a-search-logic-problem/123460 "2007-12-17T23:55:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ReidO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@ReidO](https://www.ruby-forum.com/u/ReidO)\
**Post date:** [December 17, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/need-help-with-a-search-logic-problem/123460/1 "2007-12-17T23:55:18Z")

</div>

I’m of course a Ruby noob, but not only that I’m a programing noob, so  
I think I would have this problem no matter what language I’m working  
with. I’m trying to do a search for my website and can do listings of  
properties no problem but I’m having a huge problem when trying to do  
a search. I’ve been reading RailsSpace by Hartl and Prochazka which  
is a great book and has gotten me a long way in learning Ruby and  
programing but here is my problem. I am trying to use a default  
search for ALL cities that match the criteria. When it defaults to a  
city or someone chooses a city the search works fine, but it’s the ALL  
cities options that is giving me fits. Here is the code I’m working  
with. Any help would be greatly appreciated:

## Property Model:

def self.find\_by\_pcc(params)  
where = []  
unless params[:mls].blank?  
where \<\< “mls = :mls”  
end  
unless params[:category].blank?  
where \<\< “category = :category”  
end  
unless params[:bedroom].blank?  
where \<\< “bedroom \>= :bedroom”  
end  
unless params[:bathroom].blank?  
where \<\< “bathroom \>= :bathroom”  
end  
unless params[:min\_price].blank?  
where \<\< “price \>= :min\_price”  
end  
unless params[:max\_price].blank?  
where \<\< “price \<= :max\_price”  
end  
unless params[:school].blank?  
where \<\< “school \>= :school”  
end  
where \<\< “city = :city”

if where.empty?  
[]  
else  
find(:all,  
:conditions =\> [where.join(" AND "), params],  
:order =\> “city”)  
end  
end

## Controller:

def browse  
@PropCategories = [[‘Residential’,‘Residential’],  
[‘Commercial’,‘Commercial’],[‘Land’,‘Land’],[‘Rental’,‘Rental’]]  
@PropCities = [[‘All Cities’, ‘:all’],[‘Bassfield’, ‘Bassfield’],  
[‘Yada’,‘Yada’], [‘Heidelberg’,‘Heidelberg’]]  
@PropSchools = [[‘Any’,‘nil’],[‘test’,‘test’],[‘alpha’,‘alpha’],  
[‘beta’,‘beta’]]  
@title = “Browse”  
return if params[:commit].nil?  
@properties = Property.find\_by\_pcc(params)  
else  
render(:action =\> ‘property\_table’)  
end  
end

## View:

\<label for “city”\>City:&nbsp;  
\<%= select “city”, params[:city],@PropCities %\>

Right now I don’t get an error, I just get a blank screen. Any help  
or advice would be greatly appreciated.

Thanks!
