0

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?

stevec
  • 41,291
  • 27
  • 223
  • 311

1 Answers1

0

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 %>
stevec
  • 41,291
  • 27
  • 223
  • 311