title: Rails4: Is it possible to do an optional ActiveRecord search?
body: <p>Say i had a record in my database like</p>
  
  <pre><code>+----+-----------+----------+
  | id | firstname | lastname |
  +----+-----------+----------+
  |  1 | 'Bill'    | nil      |
  +----+-----------+----------+
  </code></pre>
  
  <p>(note last name is nil)</p>
  
  <p>Is there any where I can retrieve the above record using the following hash structure as search parameters:</p>
  
  <pre><code>vals = {firstname: "Bill", lastname: "test"}
  Table.where(vals)
  </code></pre>
  
  <p>(ie: find the closest match, ignoring the nil column value in the table)</p>
  
  <p>(I'm thinking of checking each key in the hash individually and stopping when a match is found, but just wondering if there is a more efficient way, specially for larger tables)</p>