title: Composing a dynamic Rails where clause
body: <p>The following logic in a controller action logic determines a single attribute to be looked up via the variable <code>zone</code>  (one of <code>delivery</code>, <code>pickup</code>, <code>zone_1</code>, <code>zone_2</code>, <code>zone_3</code>, <code>zone_4</code>, <code>zone_5</code>, <code>zone_6</code> ...)</p>
  <pre><code>  if !zone_user.nil? &amp;&amp; deliver?
      zone = &quot;zone_&quot; + zone_user.sequence
    elsif zone_user.nil? &amp;&amp; deliver?
      zone = 'delivery'
    else
      zone = 'pickup'
    end
  </code></pre>
  <p>However the query cannot be stated as such</p>
  <pre><code>day_slot = Day_slot.order(id: :asc).
     where(['day_id IN (?) AND slot_id IN (?) AND zone = ?', @day, @slots, true]).all
  </code></pre>
  <p>since <code>column &quot;zone&quot; does not exist</code>.</p>
  <p>How should this query be composed?</p>