使用Rails 3 link_to进行ajax回调的正确方法是什么

这是场景。

简介:我有一个解决方案,但我想知道这是否是在Rails 3中使用AJAX回调的最佳方法。

问题:我有一个链接,当点击它应该使用AJAX更新页面上现有的html元素(在我的情况下是div ):

Change Goes here

我的解决方案在我的projects/show.html.erb

是的}%>

我的TasksController如下:

 class TasksController < ApplicationController def index respond_to do |format| format.html format.js { render action: "index", script: true } end end end 

在我的tasks/index.js.erb我有

$(“#project_content”)。html(“’tasks’)%>”);

问题:这一切都有效。 但为什么我必须做所有这些? 不存在(或者不存在)解决方案,我们所有人都习惯于这样做

true, :update=>"project_content"} %>

然后,这会将tasks/index.js.erb加载到密钥:update引用的任何元素中?

你试图从旧的Rails 2.3重新发明link_to_remote 。 这种解决方案通常过于复杂和僵化。

我在这里找到了答案

令人遗憾的是,此function已从Rails 3中删除。