In rails 2 for a ajax form we can have ajax callbacks like before, after etc. How to do it in rails 3.
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
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With