真的很简单。在您看来,有这样的链接/按钮。重要的一点是 :remote = > true
<%= link_to 'Update Thingy', update_thingy_path, :confirm => 'You sure you wanna update?', :remote => true %>
要么
<%= button_to('Update Thingy', {:action => 'update_thingy', :thingyid => 314}, :method => :get, :remote => true) %>显然,您必须获取update_thingy_path才能正常解决某些问题。区别在于渲染时将渲染 .js.erb而不是
.html.erb。在该update_thingy.js.erb中,您只需将要运行的任何javascript放在客户端中即可。您可能想通知用户该更新已发生(例如,在jQuery中):
$('#notice').html("Thingy was update.")或者,如果您要返回的任何Javascript都非常简单,则在控制器中,您可以执行以下操作,而不必为一个代码行添加整个js.erb。
render :js => "alert('Blah')"


