Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting ajax:failure in Rails 3 forms

I am currently working with a form in rails 3 and I am running into a totally weird situation. Basically, the form detects a successful return, but fails to detect a "400" error. Here is some code.

JQUERY:

$(".editorial_review").live('ajax:failure', function(xhr, status, error) {
         alert('error');
        })
    .live('ajax:success', function(){$(this).parents('tr').prev('tr.main').fadeOut(); $(this).parents('tr').fadeOut(); });
  });  

RAILS:

 def create
    render :json => {:error => 'No Final Status Selected'},:status => 400 and return if params[:status].blank?
    @success = send(params[:status].gsub(' ', '_'))
    respond_to do |format|
      format.js {head:ok}
    end
  end  

HAML:

-semantic_form_for EditorialReview.new, :remote=>true do |f|

I've checked in firebug, and everything seems kosher, and indeed when the controller responds with head :ok there are no problems to speak of.

Any help would be much appreciated. Thanks!

like image 351
Dave G Avatar asked Mar 02 '11 17:03

Dave G


1 Answers

The jquery rails.js uses ajax:error instead of ajax:failure. Try that

like image 133
Suan Avatar answered Oct 14 '22 23:10

Suan