Rails tip: Additional content for a layout

Article source on GitHub

If you need to add additional content to your layout, you can have named content_for blocks. Great for including additional page-specific javascript files.

In application.erb:

<!-- snip -->
<%= javascriptincludetag :defaults %>
<%= yield :javascript %>
<!-- snip -->
Then inside your view, you can:
<% contentfor :javacript do %>
  <%= javascriptinclude_tag 'view-specific.js' %>
<% end %>