title: How to return only one object in "where" statement with Rails?
body: <p>While creating a Rails app I have a common problem of finding a unique object in database that matches some conditions. And if there is more than one result, some kind of error needs to be triggered.
  I do it like this right now:</p>
  
  <pre><code>results = ModelName.where(attr1: condition1, attr2: condition2)
  raise "too many ModelName objects for condition" if results.count &gt; 1
  unique_result = results.first
  </code></pre>
  
  <p>But it seems too verbose for such a common task. It would be nice to only have to write something like this:</p>
  
  <pre><code>unique_result = ModelName.unique_where(attr1: condition1, attr2: condition2)
  </code></pre>
  
  <p>Is there a method that returns the record if it is unique or raises an exception if more than one record is found without manually extending ActiveRecord?</p>