Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Conditionally Execute JavaScript in the Asset Pipeline

View Gemfile
1 2
# https://github.com/gazay/gon
gem 'gon'
View Gemfile
1 2 3 4 5 6 7 8 9 10 11
class ApplicationController < ActionController::Base
before_filter :set_gon
 
# ...
 
private
def set_gon
gon.page = "#{params[:controller]}_#{params[:action]}"
end
end
end
View Gemfile
1 2 3 4 5 6 7
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!"
View Gemfile
1 2 3 4 5 6 7
!!! 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
Something went wrong with that request. Please try again.