title: Rails 3: How to return errors in a JSON request?
body: <p>How can I return a 800, 404, etc error when a user makes a JSON/XML request to my API?</p>
  
  <p>I've tried</p>
  
  <pre><code>error 404, {:error =&gt; "ERror".to_json }
  </code></pre>
  
  <p>with no success.</p>
  
  <p>Also, I've tried to put a "respond_to" but it doesn't work as well (it duplicates the respond_to and gives error).</p>
  
  <p>Thanks</p>