Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Created November 14, 2012 08:08
Show Gist options
  • Save ethagnawl/4070926 to your computer and use it in GitHub Desktop.
Save ethagnawl/4070926 to your computer and use it in GitHub Desktop.
Conditionally Execute JavaScript in the Asset Pipeline
class ApplicationController < ActionController::Base
before_filter :set_gon
# ...
private
def set_gon
gon.page = "#{params[:controller]}_#{params[:action]}"
end
end
end
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!"
# https://github.com/gazay/gon
gem 'gon'
!!! 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