【问题标题】:Use content_for with src attribute of a script tag?将 content_for 与脚本标签的 src 属性一起使用?
【发布时间】:2020-12-04 13:24:51
【问题描述】:

我想出了如何将content_for 用于某些元素,例如<title>

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

但是当我需要注入带有src 属性的&lt;script&gt; 标记时,我似乎无法让它工作。 IE。这段代码:

<script src="https://js.stripe.com/v3/"></script>

如何使用content_for 在页面的head 中放置脚本标签(带有src 属性)?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-6 content-for


    【解决方案1】:

    另一个论坛的回答

    将此添加到您的脑海中

    <%= yield :whatever_name_you_want %>
    

    并将其添加到您的模板/视图中:

    <% content_for :whatever_name_you_want do %>
       <script src="https://js.stripe.com/v3/"></script>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多