In Rails, the common idiom for page-specific Javascript is:
(layout)
<head>
<% yield :javascript %>
</head>
(view)
<% content_for :javascript do %>
<script type="text/javascript">
$().whatever;
</script>
<% end %>
I hate repeating the script tags. Is there any reason why the following is a bad idea?
(layout)
<head>
<script type="text/javascript">
<% yield :javascript %>
</script>
</head>
(view)
<% content_for :javascript do %>
$().whatever;
<% end %>
I agree that it’s what is most specific to your use case. Generally, when I use the <% yield :javascript %>, it’s purpose is to add in page specific libraries, which would be a limitation to the approach you proposed. If you want to support both, I have done the following:
(layout)
(view)
Of course most people put javascript libraries at the bottom for optimization of page loading, so then you could just move it in your layout.