【发布时间】:2012-03-11 13:00:50
【问题描述】:
这是场景。
总结: 我有一个解决方案,但我想知道这是否是让 AJAX 回调在 Rails 3 中工作的最佳方式。
问题:
我有一个链接,点击它应该使用 AJAX 更新页面上现有的 html 元素(在我的情况下为 div):
<div id="project_content">Change Goes here</div>
我的解决方案
在我的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')%>");
问题: 这一切都有效。但为什么我必须做这一切?不存在(或不存在)过去我们所有人都可以简单地执行此操作的解决方案
<%= link_to "tasks", project_tasks_path(@project), {:remote=>true, :update=>"project_content"} %>
然后这会将tasks/index.js.erb 加载到键:update 引用的任何元素中?
【问题讨论】:
标签: ruby-on-rails ajax ruby-on-rails-3 link-to