I am trying to build a dynamic where clause for a search page and this is the code I am using:
Code:
def search
	conditions = ['1=1']
	
	conditions << 'lastname = [:voter][:lastname] %' if params[:voter][:lastname]
	conditions << 'firstname = [:voter][:firstname] %' if params[:voter][:firstname]
	
	@search_result = Voter.find(:all,
			:conditions => [conditions.join(' and '), params])
  end
This code is not working and I think it is a syntax problem again. Here is the error that is produced:wrong number of bind variables (5 for 3) in: 1=1 and lastname = [:voter][:lastname] % and firstname = [:voter][:firstname] % and here are the parameters tht are being passed:
Code:
Parameters: {"voter"=>{"lastname"=>"Smith", "gender"=>"M", "firstname"=>"Richard", "ph_home"=>"000-000-0000"}, "commit"=>"Search", "residence"=>{"city"=>"", "number"=>"", "streetname"=>"", "postalcode"=>"", "streettype"=>""}}
Because I am only testing this right now I am only defining two variables in the conditions - the rest I will add later once I get this part to work. Can someone help me with the syntax or other suggestions.

Rick