rails3中的Ajax回调

Pra*_*vin 8 ruby-on-rails-3

在用于ajax形式的rails 2中,我们可以使用像之前,之后的ajax回调等.如何在rails 3中执行此操作.

Fre*_*röm 17

我遇到了同样的问题,这篇文章帮助我解决了问题.基本上你需要将一个监听器附加到对rails的回调事件做出反应的元素上.例如:

<%= link_to 'Delete', post, 
  :confirm => 'Are you sure?', 
  :method => :delete, 
  :remote=>true, 
  :id=>'delete' %>
Run Code Online (Sandbox Code Playgroud)

在一个单独的js文件中(使其不引人注目),使用jQuery:

$('#delete').bind('ajax:success', function() {
  // do something
});
Run Code Online (Sandbox Code Playgroud)