title: How to parameterize a date range in a rails (postgres) query?
body: <p>Just like the title asks, how do I include a date range in a query?</p>
  
  <p>For example, let's say I have a model called <code>VisitToGrandma</code> and it has a field called <code>visit_date</code>. Now, I want to find all visits to grandmothers that happened in the last month.</p>
  
  <p>Here is what I'm trying:</p>
  
  <pre><code>VisitToGrandma.where("? @&gt; visit_date", (1.month.ago..Time.now))
  </code></pre>
  
  <p>However, this produces the query:</p>
  
  <blockquote>
    <p>SELECT "visits_to_grandmas".* FROM "visits_to_grandmas" WHERE ('2018-07-01','2018-07-02','2018-07-03','2018-07-04','2018-07-05','2018-07-06','2018-07-07','2018-07-08','2018-07-09','2018-07-10','2018-07-11','2018-07-12','2018-07-13','2018-07-14','2018-07-15','2018-07-16','2018-07-17','2018-07-18','2018-07-19','2018-07-20','2018-07-21','2018-07-22','2018-07-23','2018-07-24','2018-07-25','2018-07-26','2018-07-27','2018-07-28','2018-07-29','2018-07-30','2018-07-31','2018-08-01' @> visit_date)</p>
  </blockquote>
  
  <p>What's the correct way to parameterize this?</p>
  
  <p><em>Yes, I know for this fictional example, I can just use the start and end date and use <code>BETWEEN</code> or some other operators to do this without using an actual date range, but that's not what I'm asking about.</em></p>
  
  <p>Edit to point out how this question is different from <a href="https://stackoverflow.com/questions/20413456/rails-activerecord-query-date-range" title="this one">the other question</a>:</p>
  
  <p>That question is just about finding a date in a range, my question is asking how to actually parameterize a range object so that all of postgresql's daterange operators can be used.</p>