Is there an accepted way for generating the javascript in the application layout, dependent upon what the controller/action is?
content_for
is the right way to go about here. Based on the current action you could include javascripts required for the particular view. Also however it should be only in the head as loading javascripts in the middle of the page is considered to be obtrusive and hence have a content for in the head of the page. like
<head> <%= yield :dynamic_javascripts %> </head>
and
<% content_for :dynamic_javascripts do %>
<%= javascript_include_tag "javascript.js" %>
<%end%>
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