Keeping javascript in the <head>

Given that Rails has built in ways to do almost everything else :slight_smile: , is
there a way to keep view specific javascripts inside the head tag of a
layout without having to include that javascript on every page?

make your include tag dynamic. I can’t remember the exact syntax but
you’ll get the picture.

<%= include_javacripts, ****** #{@my_javascript} %>

in your view do something like this:
<% @my_javascript = ‘view_specifiic_javascript.js’ %>

Charlie B.
recentrambles.com

In your , put:

<%= @content_for_page_scripts %> Then in your view: <% content_for("page_scripts") do -%> function item_added() { var item = $('items').lastChild; new Effect.Highlight(item, { startcolor:'rgb(255,153,255)', endcolor:'rgb(200,200,200)' }); Element.hide('busy'); $('form-submit-button').disabled = false; $('item-new-code').value = ''; $('item-new-description').value = ''; Field.focus('item-new-code'); } function item_loading() { $('form-submit-button').disabled = true; Element.show('busy'); } <% end -%> Then the stuff will be in the header on the delivered page, but close to where you need in in your .rhtml files. content_for() works for other stuff, too! -Rob Rob B. http://agileconsultingllc.com [email protected] +1 513-295-4739

thanks for the great tip. I had no idea about the @content_for command.