Created
November 14, 2012 08:08
-
-
Save ethagnawl/4070926 to your computer and use it in GitHub Desktop.
Conditionally Execute JavaScript in the Asset Pipeline
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
class ApplicationController < ActionController::Base | |
before_filter :set_gon | |
# ... | |
private | |
def set_gon | |
gon.page = "#{params[:controller]}_#{params[:action]}" | |
end | |
end | |
end |
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
if gon.page is 'foo_bar' | |
$ -> | |
alert "Top o' the mornin' to ya'!" | |
if gon.page is 'foo_baz' | |
$ -> | |
alert "... and Bob's your uncle!" |
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
# https://github.com/gazay/gon | |
gem 'gon' |
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
!!! 5 | |
%html | |
%body | |
%h1 Foo | |
= yield | |
= include_gon | |
= javascript_include_tag 'application' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment