# Working with an array of search parameters

**URL:** <https://www.ruby-forum.com/t/working-with-an-array-of-search-parameters/110979>\
**Category:** Rails\
**Created:** [August 1, 2007, 5:38pm UTC](https://www.ruby-forum.com/t/working-with-an-array-of-search-parameters/110979 "2007-08-01T17:38:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [August 1, 2007, 5:38pm UTC](https://www.ruby-forum.com/t/working-with-an-array-of-search-parameters/110979/1 "2007-08-01T17:38:46Z")

</div>

Hi!

I have a search form where user may search by one or a combo of these  
items:  
Last Name  
First Name  
Alias Last Name  
Alias First Name  
Case Number

First of all, how do I set up the fields in \_form to return an array  
to the controller?

Secondly, how do I access the array in the controller and generate an  
appropriate “find” statement based on what array elements were passed  
in?

As it stands now, I’m setting each parameter to a variable and then in  
a giant “if” statement constructing the “find” statement. This worked  
ok with just name and case number to search for. Now that I’ve added  
alias to the mix, this is turning into some majorly UGLY code. Too  
many possible combinations!

Any thoughts/suggestions/ideas are welcomed and appreciated.

Thank you!! ~Ali

---

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [August 2, 2007, 4:25am UTC](https://www.ruby-forum.com/t/working-with-an-array-of-search-parameters/110979/2 "2007-08-02T04:25:53Z")

</div>

you can use the criteria\_query plugin to make life a little easier:  
[http://agilewebdevelopment.com/plugins/criteria\_query](http://agilewebdevelopment.com/plugins/criteria_query)

I tried using it myself, but ended up falling back on multiple if  
statements and building the conditions string and params array by  
hand, since in pretty much every case, I need paginate my result set,  
which criteria query won’t let you do.

Here’s some example code from my search action in one of my  
controllers, to show you my approach:

[http://pastie.caboo.se/84234](http://pastie.caboo.se/84234)

I stored each search parameter into an ivar so when the page is  
redisplayed, the search terms will still be filled out in my search  
form…

Adam
