I usually have the following in the layout file:
<%= javascript_include_tag :defaults %>
<%= @extra_head_content %>
And then in the views:
<% (@extra_head_content ||= "") += capture do %>
<%= other_content %>
<% end %>
See the API documentation for #capture