title: How to chain scopes with ransack queries
body: <p>A user submits a ransack query for finding <code>employers</code>.  I want to first use a <code>scope</code> to filter down the records in the <code>employers</code> table, and then I want to run the ransack query on that <code>activerecord::relation</code> object returned from that <code>scope</code>. </p>
  
  <p>Specifically in that order.  It is important that the <code>scope</code> is run first because it returns only a select number of records which the ransack query can then further filter down.  In my situation, running the ransack query first and then running the <code>scope</code> query on the return runs very slow because the ransack query may return many many records.</p>
  
  <p>This sounds like the job of chaining queries together.  I know how to chain regular scopes together:</p>
  
  <pre><code># example
  # `active`, `from_department_stores`, and `small_company` are all scopes
  @employers = Employer.active.from_department_stores.small_company 
  </code></pre>
  
  <p>But I do not know how to chain ransack queries onto scopes, and do it in a manner where the scope is run first.</p>
  
  <p>Code:</p>
  
  <pre><code>@q = Employer.ransack(params[:q])
  # Pretty sure this will not work, but hopefully it provides a good idea
  # of what I am trying to do
  @employers = Employer.active.@q.result
  </code></pre>
  
  <p><a href="https://github.com/activerecord-hackery/ransack" rel="nofollow">Ransack Documentation</a></p>