Skip to content

Instantly share code, notes, and snippets.

@brianng
Created December 4, 2009 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianng/248728 to your computer and use it in GitHub Desktop.
Save brianng/248728 to your computer and use it in GitHub Desktop.
Autowire view-specific Javascript (Erector)
class Views::Layouts::Application < Erector::Widgets::Page
# Include view-specific "onready" Javascript, if present
def head_content
super()
javascript_filename = "#{self.class.model_name.singular[/^views_(.+)/,1].gsub(/_/, '.')}.onready.js"
if File.exist? "#{ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR}/#{javascript_filename}"
javascript_include_tag javascript_filename
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment