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.
<quote>
ActiveRecord::PreparedStatementInvalid in StoreController#search
wrong number of bind variables (1 for 2) in: first_name like ? and
last_name like ?
</quote>
<quote>
def self.find_lead(vin_type, vin_text, fname_type, fname_text,
lname_type, lname_text, li_type, li_text, email_type, email_text)
if vin_type == "equals"
op1 = "="
else
op1 = "like"
end
if fname_type == "equals"
op2 = "="
else
op2 = "like"
end
if lname_type == "equals"
op3 = "="
else
op3 = "like"
end
if li_type == "equals"
op4 = "="
else
op4 = "like"
end
if email_type == "equals"
op5 = "="
else
op5 = "like"
end
front_value_modifier = {"equals" => "",
"contains"=> "%",
"begins_with"=> "", "ends_with"=>
"%"}
back_value_modifier = {"equals" => "",
"contains"=> "%",
"begins_with"=> "%", "ends_with"=>
""}
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
</quote>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---