Rails jQuery UJS callbacks not starting

I am trying to activate the ajax: success callback for a remote link. I am on Rails 3.0.8 and jquery-rails 1.0.11. I ran a jquery generator to install javascripts. Both jquery and jquery_ujs are included in my default settings, and I can verify that they are included in the page.

Here is my javascript:

jQuery(function($) { $("#deactivate") .bind("ajax:success", function() { alert("HELLO"); }) .bind("ajax:error", function() { alert("GOODBYE"); } ); }); 

Link:

 = link_to 'Deactivate', activate_patient_path(patient), :id => 'deactivate', :class => "button button-red", :remote => true 

Activation Action:

 def activate patient = Patient.find(params[:id]) patient.do_not_call = !patient.do_not_call if patient.save render :nothing => true else render :status => 500, :nothing => true end end 

It seems that the ajax call is working fine. The action is triggered and I see the changes in the database. However, ajax callbacks do not start. I can not get them to work. I can get other events, such as a click, to work just fine.

If I debug rails_ujs in Firebug, I see that the following code runs from the ajax Rails block:

 success: function(data, status, xhr) { element.trigger('ajax:success', [data, status, xhr]); } 

I'm at a dead end. Any ideas?

+6
source share
1 answer

make sure you don't turn on jquery.js again after rails.js ... I ran into a similar problem when jquery.js was turned on twice and rails.js was turned on between them.

+12
source

Source: https://habr.com/ru/post/890885/


All Articles