Use content_for with src attribute of a script tag?

♀尐吖头ヾ 提交于 2021-01-29 08:03:44

问题


I figured out how to use content_for for some elements, for example <title>:

<% content_for :title, "Hi, I'm #{@user.username}" %>

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>

How can I use content_for to place a script tag (with src attribute) in the head of a page?


回答1:


Answer from another forum

Add this to your head

<%= 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 %>


来源:https://stackoverflow.com/questions/65138243/use-content-for-with-src-attribute-of-a-script-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!