Filter search in Rails
===

I have an Organization resource that I want to do search on using filters in the UI. I have an Organization model, and a Sector model in a many-to-many relationship. The join model is OrganizationSector. I have my app/view/organizations/index.html that features the following elements :

- have the list of possible filters on the side, that can be clickable 
- a search bar
- an organization index (Organization.all when one hits GET /organizations)

Say I do the following : click on a filter (filter #1), then another filter (filter #2). 

After the first click, I want the organization index to change to <code>Sector.find(params[:filterid]).organizations</code> (this I have) 

After the second click (that's where I'm stuck), I want the index to change to 
<pre><code>
select * from Organization as os, OrganizationSector as o where os.org_id = o.id and os.sector_id in (1,2)
</code></pre>

Then I want the search to be taken into account in the search (obviously)

My search form is the following :


    <%= form_tag organizations_path, method: 'get', :id => 'search_orgs', class: 'form-search form-big-search' do%>
    <p>
     <%= text_field_tag :search, params[:search], class: 'big-search-query' %>
     <%= hidden_field_tag :filters, params[:filters], class: 'big-search-query' %>
     <%= hidden_field_tag :filters_id, params[:filters_id], class: 'big-search-query' %>
     <%= submit_tag "Search", class: 'btn btn-primary btn-big-search pull-right', name: 'nil'%>
    </p>
    <% end %>

I am able to use filter ids one at a time, but not do 2 at once. Also, I don't know what to write in my search method in my Organization model to fetch organizations whose sectors match the search.

If someone could help me with that (controller and model), that'd be really awesome. I'm really confused now.

