title: Ruby on rails. Ransack search associations
body: <p>I'm getting a little stuck with a ransack search form.</p>
  
  <p>I need to search through a model's association, and bring results back when <code>name_cont</code> BUT ONLY WHEN AN associated model's <code>status == something</code>.</p>
  
  <p>I have a <code>gig</code> model with a <code>has_many</code> <code>belongs_to</code> relationship with a <code>request</code> model and <code>user</code> model. The <code>request</code> model has attributes <code>status</code> and the <code>user</code> model has attributes <code>publicname</code>. I want to search <code>publicname_cont</code> and only show results from the requests that have a <code>status == "hired"</code>.</p>
  
  <p>Currently my search brings back the results of <code>publicname</code> regardless or the <code>request</code> models <code>status</code>.</p>
  
  <hr>
  
  <p>Gigs Controller:</p>
  
  <pre><code>@gigs = @q.result(distinct: false).notexpired.order(date: :asc).page(params[:page]).per(20)
  </code></pre>
  
  <p>Search form:</p>
  
  <pre><code>&lt;%= search_form_for @q, url: welcome_index_url, remote: false do |f| %&gt;
  
        &lt;%= text_field_tag :search, params[:search], class: 'loc-search', placeholder: "Location"%&gt;
        &lt;%= f.search_field :locationname_cont, placeholder: "Bar name" %&gt;
        &lt;%= f.search_field :requests_user_publicname_cont, placeholder: "Band name" %&gt;
        &lt;%= f.submit %&gt;
   &lt;% end %&gt;
  </code></pre>
  
  <p>Currently, I can search <code>requests_user_publicname_cont</code> and it gives me all the results as expected where the parameters match. 
  I am looking for a way to search <code>requests_user_publicname_cont</code> AND <code>requests_status_eq, ("hired")</code></p>
  
  <hr>
  
  <p>I am not sure how to go about this, any help would be appreciated, thanks.</p>