Skip to content

Instantly share code, notes, and snippets.

@neckhair
Created June 29, 2016 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neckhair/ef70408f5f2f35275ba24c6efcd665d0 to your computer and use it in GitHub Desktop.
Save neckhair/ef70408f5f2f35275ba24c6efcd665d0 to your computer and use it in GitHub Desktop.
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