$request = request
When I write this in controller, it will work. But if i need this variable in Model or Application controller, How can i ?
if you use rails > 5.0, you can do below
add a module in models/concern
module Current
thread_mattr_accessor :actor
end
in applicaton_controller do
around_action :set_thread_current_actor
private
def set_thread_current_actor
Current.actor = current_user
yield
ensure
# to address the thread variable leak issues in Puma/Thin webserver
Current.actor = nil
end
then in thread anywhere get current_user
Current.actor