Topic: Different view result according to filter and text box

Hi folks,

Googled a lot about this one. Maybe i'm missing something here...

The scenario:

I have an index page with:
date filter | department filter | text_box(user) | text_box(phone_number)

The filters and text_box are going to filter a Model X.

Depending on the user input I have 3 possible views:

Default: no input -> I show view 1
Data filtered by date -> result 1 with (date filtered)
department filter -> view 2
department filter + user -> view 3
.....

also:
if the user filters by department the text_box(user) changes to a filter(listing the users from this department)

What i'm doing.
Checking params and showing the view according to result but with this i end up with a lot of ifs...
so i have the impression that i'm doing it the wrong way...

thanks in advance!

Re: Different view result according to filter and text box

Hello

I guess if you have to use complex filters on objects, which is a kind of "search all the elements responding to the criterias" you should use a "search gem" like Ransack...
There's an excellent step-by-step tutorial available on RailsCasts: http://railscasts.com/episodes/370-ransack

Hope this can help you
Cheers

Re: Different view result according to filter and text box

Thanks anso!

I forgot to mention that i'm using ransack but i didn't find a "nice" way to use it with "my cenario".
I'm gonna take a look again at the Ransack complex search example...

cheers!