Skip to content

Instantly share code, notes, and snippets.

@devpuppy
Created December 8, 2009 17:20
Show Gist options
  • Save devpuppy/251817 to your computer and use it in GitHub Desktop.
Save devpuppy/251817 to your computer and use it in GitHub Desktop.
Per-template javascript include tag
# useful for organizing unobtrusive javascript per template
# assumes layout has yield :javascripts
# need to figure out how to invoke from the template without explicitly having to call it
def javascript_template_include_tag
javascript_path = "views/#{@template.template.path_without_format_and_extension}.js"
if File.exist?(File.join(RAILS_ROOT, 'public', 'javascripts', javascript_path))
content_for :javascripts do
javascript_include_tag javascript_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment