# Multiple form fields for condition statement

**URL:** <https://www.ruby-forum.com/t/multiple-form-fields-for-condition-statement/123457>\
**Category:** Rails\
**Created:** [December 17, 2007, 11:36pm UTC](https://www.ruby-forum.com/t/multiple-form-fields-for-condition-statement/123457 "2007-12-17T23:36:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickmc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4af34b/32.png) [@nickmc](https://www.ruby-forum.com/u/nickmc)\
**Post date:** [December 17, 2007, 11:36pm UTC](https://www.ruby-forum.com/t/multiple-form-fields-for-condition-statement/123457/1 "2007-12-17T23:36:27Z")

</div>

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#search

wrong number of bind variables (1 for 2) in: first\_name like ? and  
last\_name like ?

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

---

<div class="post-metadata">

**Author:** ![nickmc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4af34b/32.png) [@nickmc](https://www.ruby-forum.com/u/nickmc)\
**Post date:** [December 17, 2007, 11:52pm UTC](https://www.ruby-forum.com/t/multiple-form-fields-for-condition-statement/123457/2 "2007-12-17T23:52:22Z")

</div>

sorry, the at the very bottom of the code, it should be w = [v,x] not w  
= [v,w]

> 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
