I'm trying to load some javascript in my application page using a named yield block, but the code is duplicated because of a generic yield that load my view pages. something like that:
-----Code present in views-----
<% content_for :bottom_scripts do %>
<script type="text/javascript">
Some Javascripts
</script>
<% end %>
------Code in my application page-----
<div id = "body">
<%= yield %>
</div>
<%= yield :bottom_scripts %>
The script code is printed twice, but I need it just printed in the second yield, any thoughts?
you can use content_for
in your layout instead of yield
when content_for
is not passed a block it outputs the block stored at that identifier
in view:
<% content_for :foo do %>
<p>Bar</p>
<% end %>
in layout:
<%= content_for :foo %>
http://apidock.com/rails/ActionView/Helpers/CaptureHelper/content_for
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With