Reputation: 6662
In rails 2 for a ajax form we can have ajax callbacks like before, after etc. How to do it in rails 3.
Upvotes: 8
Views: 5400
Reputation: 346
Binding a function to ajax:success as morbaq suggested worked for me.
However, I think if there is more than one ajax behavior associated with the element, the function will run for each of them.
Upvotes: 1
Reputation: 2445
In case you also want to add listener for ajax send use following code
$(document).ready(function() {
$('#topnav-buildings').bind('ajax:beforeSend', function() {
blockDiv('#topnav-buildings');
});
});
I spent an hour to find these t2 things
Upvotes: 0
Reputation: 1511
I'm having the same problem, and this post helped me figure it out. Basically you need to attach a listener to the element that reacts on rails' callback events. For example:
<%= link_to 'Delete', post,
:confirm => 'Are you sure?',
:method => :delete,
:remote=>true,
:id=>'delete' %>
In a separate js file (to make it unobtrusive), with jQuery:
$('#delete').bind('ajax:success', function() {
// do something
});
Upvotes: 17