stevec
stevec

Reputation: 52268

Use content_for with src attribute of a script tag?

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?

Upvotes: 0

Views: 114

Answers (1)

stevec
stevec

Reputation: 52268

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

Upvotes: 0

Related Questions