Created
September 27, 2012 16:06
-
-
Save kormie/3794850 to your computer and use it in GitHub Desktop.
My method for page specific JS
This file contains hidden or 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
| window.FooPageJavaScript = class FooPageJavaScript | |
| constructor: -> | |
| @setupPage() | |
| @bindEvents() |
This file contains hidden or 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
| module ApplicationHelper | |
| def load_page_specific_javascript_class(javascript_class) | |
| content_for :javascript do | |
| javascript_tag "$(function(){ new #{javascript_class} })" | |
| end | |
| end | |
| end | |
| # A call to yield: javascript is placed at the bottom of the application layout file |
This file contains hidden or 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
| - load_page_specific_javascript_class "FooPageJavaScript" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've improved on it slightly since then ;) https://gist.github.com/phillc/11184246