title: Rails - Success callback is triggered on status: 422 response
body: <p>I send ajax request:</p>
  
  <pre><code>$ -&gt;
    $('#delete_product').dialog
      buttons:
        "Confirm": -&gt;
          $(this).dialog('close')
          $.ajax
            url: '/products/' + $('#delete_product').data('current_product').attr('product_id'),
             type: 'POST',
             data: _method: 'DELETE',
             dataType: "json",
             success: -&gt;
               $('#delete_product').data('current_product').fadeOut(200)
             error: -&gt;
               alert('Error')
         "Cancel": -&gt;
           $(this).dialog('close')
       autoOpen: false
  
     $('.delete-product').click -&gt;
       current_product = $(this).closest('tr')
       $('#delete_product').data('current_product', $(current_product))
  
       $('#delete_product').dialog('open')
  </code></pre>
  
  <p>In controller I have:</p>
  
  <pre><code>def destroy
    render json: @product, status: 422
  end
  </code></pre>
  
  <p>Firstly alert appears, then after clicking on OK button on the alert, the row is faded out. Seems that success callback was called after error one.</p>
  
  <p>Thank you for any help!</p>