simple search in rails

Posted by Adnan on Stack Overflow See other posts from Stack Overflow or by Adnan
Published on 2010-03-15T12:58:46Z Indexed on 2010/03/15 12:59 UTC
Read the original article Hit count: 152

Filed under:

Hi,

I'm making a simple search form in rails. In my search view I have two select boxes with fixed values like:

SELECT BOX 1          SELECT BOX 2
ALL,                  ALL,
FR,                   FR,
US,                   US,
DE                    DE

And I have 2 fields in my DB with country_from and country_to.

So for making a simple search like from FR to US I use:

@search_result = Load.find(:all, :conditions => "country_from='#{params[:country_from]}' AND country_to='#{params[:country_to]}'" )

that is fine, but I need to implement the ALL option as well, so when I make a search like from DE to ALL I get a list with all countries in country_to

I image I can do it with ifs...but what would be the most efficient way to do it?

© Stack Overflow or respective owner

Related posts about ruby-on-rails