将 content_for 与脚本标签的 src 属性一起使用? [英] Use content_for with src attribute of a script tag?
本文介绍了将 content_for 与脚本标签的 src 属性一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想出了如何将 content_for
用于某些元素,例如
:
I figured out how to use content_for
for some elements, for example <title>
:
<% content_for :title, "Hi, I'm #{@user.username}" %>
但是当我需要注入带有 src
属性的 <script>
标签时,我似乎无法让它工作.IE.这段代码:
But I can't seem to get it working when I need to inject a <script>
tag with src
attribute. I.e. this code:
<script src="https://js.stripe.com/v3/"></script>
如何使用 content_for
在页面的 head
中放置脚本标记(带有 src
属性)?
How can I use content_for
to place a script tag (with src
attribute) in the head
of a page?
推荐答案
来自其他论坛的回答
将此添加到您的脑海中
<%= yield :whatever_name_you_want %>
并将其添加到您的模板/视图中:
And add this to your template/view:
<% content_for :whatever_name_you_want do %>
<script src="https://js.stripe.com/v3/"></script>
<% end %>
这篇关于将 content_for 与脚本标签的 src 属性一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文