A simple way to do this is to add these lines to your application.html.erb file after the main JS includes:
and then add a block similar to this in each view template that needs custom JS.
<% end %>
Here is a real example that uses the facebox jQuery plugin which provides 'light box' functionality. This code is placed at the top of my 'show' template.
You can take this further by also including custom stylesheets linked to these plugins in the same block. That can result CSS and JS includes being interspersed in the resulting HTML file which some people may not like, but I don't think there are any practical drawbacks to it.
loadingImage : '/images/facebox_loading.gif',
closeImage : '/images/facebox_closelabel.gif'
<% end %>
For high performance production sites you should weigh the benefits of this approach in terms of clarity with the performance benefit of stashing all your JS code in a single file and minifying it.