js.erb 呈现到布局中,而不是执行
js.erb rendered into layout, not executed
我正在尝试使用简单的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?
app/controllers/admin_controller.rb:
def hint
respond_to do |format|
format.js
end
end
app/views/admin/hint.js.erb:
$("#hint").text('hello coffee');
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)
我按照 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>
这让我发疯,谢谢你的帮助。
也许您遭受了 Rails 错误/功能 #10768?
也就是说,如果您的主布局被称为 application.haml
而不是 application.html.haml
,就会发生这种行为。 这是因为默认情况下,没有格式扩展名的布局会为所有格式呈现。
我可以看到您正在使用 HAML,所以我猜可能是这样。
相关文章:
- 访问布局信息是否也会导致浏览器重排
- 使用agility.js进行页面布局和合成
- 无法在通过jQuery的ajax加载的页面中执行javascript
- JavaScript执行暂时挂起页面
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 当js函数's已执行
- 哪个先执行
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- HTML表单提交时未执行外部函数
- 在Safari执行javascript之前对其进行修改
- Amd,希望确保某个东西总是最后执行
- 在Windows 10中自动执行例行程序(主要与浏览器交互)
- 同位素库错误:未捕获错误无布局模式包装生产线8
- 如何实现此布局
- 递归使用 eval() 是检查程序执行的好方法吗?
- 如何做到这一点,使代码在不传递条件后执行函数
- 如何在执行此特定onclick事件时执行JavaScript函数
- 有没有一个javascript图形绘制库可以进行气球树布局
- 如何在从浏览缓存加载页面时执行javascript
- js.erb 呈现到布局中,而不是执行