Created
June 29, 2016 06:36
-
-
Save neckhair/ef70408f5f2f35275ba24c6efcd665d0 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
class CurrentUserProvider | |
def self.instance | |
@instance = Thingy.new | |
end | |
def around(controller) | |
begin | |
Thread.current[:current_user] = controller.current_user | |
yield | |
ensure | |
Thread.current[:current_user] = nil | |
end | |
end | |
end | |
ActiveSupport.on_load(:action_controller) do | |
if defined?(ActionController::Base) | |
ActionController::Base.around_action CurrentUserProvider.instance | |
end | |
if defined?(ActionController::API) | |
ActionController::API.around_action CurrentUserProvider.instance | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment