我正在尝试使用简单的 link_to 和操作来更新跨度。从视觉上看,当我单击链接时“什么也没发生”(页面没有改变)。
查看对请求的响应,我看到我的布局,其中插入了布局生成的位置的 js.erb 文件内容。
我的环境是在 OS X 上的 Docker 下运行的 Rails 4.2,以及在 AWS 上运行的 Elastic Beanstalk。
app/views/admin/games.haml:
%p=link_to("Hint please", {:action=> "hint"}, :remote => true)
%span#hint
where next?
Run Code Online (Sandbox Code Playgroud)
应用程序/控制器/admin_controller.rb:
def hint
respond_to do |format|
format.js
end
end
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/管理/hint.js.erb:
$("#hint").text('hello coffee');
Run Code Online (Sandbox Code Playgroud)
Rails 登录请点击链接:
Started GET "/admin/hint" for 192.168.99.1 at 2016-03-14 12:04:33 +0000
Cannot render console from 192.168.99.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by AdminController#hint as JS
Rendered admin/hint.js.erb within layouts/admin (0.0ms)
Rendered application/_favicon.haml (8.9ms)
Completed 200 OK in 197ms …Run Code Online (Sandbox Code Playgroud)