Rails & # 8594; Devise & # 8594; how to access current_user from module
I am currently using Rails 3.2.9 with development 3.0.4
I can access Devise's current_user in the controller without any problem.
However, when I try to access current_user in a module like below and get an error.
c_time = DateTime.current.in_time_zone(current_user.local_timezone)
NameError (undefined local variable or `current_user 'method for DateCalculator: Module):
It would be great if someone asks for advice on what is the best way to access current_user from a module.
Thank you very much in advance.
+3
source to share
3 answers
If your module does something specific for the current subscribed user, you can follow this path
config/initializers/user_specific_time.rb
module Devise
module Controllers
module Helpers
def user_specific_time
c_time = DateTime.current.in_time_zone(current_user.local_timezone)
end
end
end
end
0
source to share