title: Find all items within a bounding box with PostGIS and Rails
body: <p>I have a Rails model that uses a PostGIS <code>POINT</code> type to store the coordinates of a location. How can I query all locations that are contained within a bounding box? The bounding box comes from Google Maps like this:</p>
  
  <p><code>/locations?within=40.766159%2C-73.989786%2C40.772781%2C-73.979905&amp;per_page=500</code></p>
  
  <p>then in my model I have a scope to handle this, but can't figure out how to get the query right:</p>
  
  <pre><code>scope :within, -&gt;(box_string) {
      sw = box_string.split(",")[0..1].reverse.map {|c| c.to_f}
      ne = box_string.split(",")[2..3].reverse.map {|c| c.to_f}
      box = "BOX3D(#{sw[0]} #{sw[1]}, #{ne[0]} #{ne[1]})"
      where( ***WHAT DO I DO HERE?*** )
    }
  </code></pre>