title: How in Sinatra would I check that the term the user has input into a form already exists in your database?
body: <p>Making a budget app while learning to use Ruby/Sinatra/SQL. Part of it involves letting the user add new vendors that they can assign transactions to. My add transaction and add vendor functions both work, but one thing I'd like to do is be able to throw up an error if the vendor that the user is trying to add - eg 'Amazon' is already in the database, before returning to my index of vendors.</p>
  
  <p>The closest that I've come to getting something working is making the name column of the vendor table UNIQUE. But if I enter a name that's already in existence in the field, I get the "PG::UniqueViolation" error.</p>
  
  <p>Is there a way to tell Sinatra that you don't want this error to flag up, you just want to redirect back to the index of vendors without the repeated value. </p>
  
  <p>My working submission form currently looks like:</p>
  
  <pre><code>&lt;div id="new-transaction"&gt;
    &lt;form action="/vendors/create" method="POST"&gt;
  
      &lt;label for="name"&gt;New vendor name:&lt;/label&gt;
      &lt;input type="text" name="name" id="vendorName" /&gt;
  
      &lt;input type="submit" value="Add new vendor" id="btn-new-vendor"&gt;
  
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>