Created
November 8, 2012 13:09
-
-
Save brumm/4038717 to your computer and use it in GitHub Desktop.
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
# ------------------------- | |
# application_controller.rb | |
# ------------------------- | |
class ApplicationController < ActionController::Base | |
before_filter :setup_gon | |
def setup_gon | |
Gon.global.controller = controller_name | |
Gon.global.action = action_name | |
end | |
end | |
# ---------------- | |
# global.js.coffee | |
# ---------------- | |
# only one dom-ready event to fire on | |
$ -> | |
# get controller and action names | |
controller = Appname.global.controller | |
action = Appname.global.action | |
# get namespace object, init and actual action method | |
namespace = Appname.controllers[controller] | |
init = namespace["init"] | |
method = namespace[action] | |
# bind 'this' to namespace to faciliate storing | |
# objects on the parent namespace, making | |
# them available to helpers and actions | |
init.call namespace if $.isFunction init | |
method.call namespace if $.isFunction method | |
# ---------------- | |
# users.js.coffee | |
# ---------------- | |
Appname.controllers = | |
users: | |
init: -> | |
@someSetting = {} | |
index: -> | |
doThing() if @someSetting? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment