gpt4 book ai didi

ruby-on-rails - 我可以在 show.html.erb 中使用 'javascript_include_tag' 和 `content_for(:head)` 吗?

转载 作者:行者123 更新时间:2023-12-03 00:04:07 25 4
gpt4 key购买 nike

为什么我会收到此错误?
我可以使用 javascript_include_tagcontent_for(:head)在 show.html.erb 中?
我想将加载js的行放在 <head>...</head>

如果我输入 <%= content_for(:head) do %> ,就不会出现加载“refresh_chat.js”的行了。
如果我删除 <%= content_for(:head) do %> ,出现加载“refresh_chat.js”的行,但<head>中没有出现

views/posts/show.html.erb

1. <%= content_for(:head) do %>
2. <%= javascript_include_tag "refresh_chat.js" %>
3. <% end %>

最佳答案

它应该可以工作。确保您yield<head>部分:

<head>
...
<%= yield :head %>
</head>

然后

<% content_for(:head) do %>
<%= javascript_include_tag "refresh_chat.js" %>
<% end %>

关于ruby-on-rails - 我可以在 show.html.erb 中使用 'javascript_include_tag' 和 `content_for(:head)` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14258273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com