Created
December 8, 2009 17:20
-
-
Save devpuppy/251817 to your computer and use it in GitHub Desktop.
Per-template javascript include tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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