int*_*att 2 javascript ajax jquery ruby-on-rails
我正在尝试使用简单的 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 (Views: 196.0ms | ActiveRecord: 0.0ms)
Run Code Online (Sandbox Code Playgroud)
我按照https://www.alfajango.com/blog/rails-js-erb-remote-response-not-executing/上的调试说明进行操作- 我没有看到 Javascript 错误。响应是布局,其中 .js.erb 的内容呈现为文本,其中yield 命令位于布局中:
<div id='main'>
<div class='header'>
<h1></h1>
<h2></h2>
</div>
<div class='content'>
$("#hint").text('hello coffee');
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这让我发疯,谢谢你的帮助。
也许您正遭受Rails bug/feature #10768 的困扰?
即,如果调用主布局application.haml而不是application.html.haml. 这是因为默认情况下会为所有格式呈现没有格式扩展名的布局。
我可以看到您正在使用 HAML,所以我猜测可能就是这样。
| 归档时间: |
|
| 查看次数: |
735 次 |
| 最近记录: |