Skip to content

Instantly share code, notes, and snippets.

@stephanschubert
Created November 6, 2009 11:34
Show Gist options
  • Save stephanschubert/227945 to your computer and use it in GitHub Desktop.
Save stephanschubert/227945 to your computer and use it in GitHub Desktop.
A small Ruby module which provides access to the current controller everywhere you could need it. Works in multithreaded environments.
module CurrentController
def self.included(base)
base.before_filter :set_current_controller
end
def set_current_controller
Thread.current[:current_controller] = self
end
end
def current_controller
Thread.current[:current_controller]
end
# Setup it up
# ActionController::Base.send :include, CurrentController
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment