I have a search form with multiple imputs and I want to build the sql
command using the find method with multiple conditions. below is the
code I’m using. When I just enter in 1 field (any of the ****value
variables) everything works out fine. but if I enter 2 or more, i get
the following message. and I have used puts statements to see what the
actual variable is that I’m passing to the :condition statement, and it
is building the array correctly, as far as I can tell. but it still
doesn’t like me. ~~
Any help is good help.
thanks.
ActiveRecord::PreparedStatementInvalid in StoreController#searchwrong number of bind variables (1 for 2) in: first_name like ? and
last_name like ?
v=""
x = []
if fname_text == ""
v=v
else
if v == ""
v="first_name #{op2} ? "
end
x <<
front_value_modifier[fname_type]+fname_text+back_value_modifier[fname_type]
end
if lname_text == ""
v=v
else
if v == ""
v="last_name #{op3} ? "
else
v=v+"and last_name #{op3} ? "
end
x <<
front_value_modifier[lname_type]+lname_text+back_value_modifier[lname_type]
end
if email_text == ""
v=v
else
if v == ""
v="email #{op5} ? "
else
v=v+"and email #{op5} ? "
end
x <<
front_value_modifier[email_type]+email_text+back_value_modifier[email_type]
end
if li_text == ""
v=v
else
if v == ""
v="leadid #{op4} ? "
else
v=v+"or leadid #{op4} ? "
end
x <<
front_value_modifier[li_type]+li_text+back_value_modifier[li_type]
end
if vin_text == ""
v=v
else
if v == ""
v="vin_number #{op1} ? "
else
v=v+"or vin_number #{op1} ? "
end
x <<
front_value_modifier[vin_type]+vin_text+back_value_modifier[vin_type]
end
w = [v,w]
if v==""
find(:all,:limit => 0)
else
find(:all,
:conditions => w,
:order => “vin_number”,
:limit => 10
)
end
end