title: Correct way of prevent duplicate records in Rails
body: <p>In my model I have this:</p>
  
  <pre><code>validates :name, :presence =&gt; true, :uniqueness =&gt; true
  </code></pre>
  
  <p>In my controller I have:</p>
  
  <pre><code>...
  if @location.save
      format.html { redirect_to @location, :notice =&gt; 'Location was successfully created.' }
      format.json { render :json =&gt; @location, :status =&gt; :created }
  ...
  </code></pre>
  
  <p>which successfully creates a record if there isn't already a record with this name in the table.  I think it's good practice to check before inserting a possibly duplicate record instead of relying on the DB constraints?</p>
  
  <p>I guess I should add something to the controller to check?  What's the correct way to do this?</p>
  
  <p>Many thanks.</p>