【发布时间】:2014-09-25 04:30:30
【问题描述】:
我有一个带有多个动作/视图的控制器,其中只有一个会利用ActionController::Live 模块。但是,一旦包含在内,AJAX 操作(在不相关的页面上)就根本不再呈现在客户端上。
以下代码可以正常运行:
my_controller.rb:
class MyController < ApplicationController
def index
// renders vanilla HTML/JS from index.html.erb
end
def update_index
// renders JavaScript from index.js.erb
end
end
index.html.erb:
<%= button_to({ controller: :my_controller, action: :update_index},
remote: true,
method: 'post') do %>
Update the text
<% end %>
<div id='content'>Some content</div>
update_index.js.erb:
$('#content').html('You clicked the button.');
问题:
一旦我将include ActionController::Live 添加到控制器,甚至在为服务器端事件创建任何JavaScript 或Rails 句柄(效果很好)之前,我现有的代码就会停止工作。发生以下情况:
- 服务器看到传入的 AJAX 请求
- 调用所有适当的控制器函数
- JavaScript 不在客户端执行。
【问题讨论】:
标签: javascript ruby-on-rails ajax html