In my User model, I have a method to display the time:
def display_time
puts "Time is: #{Time.zone.now}"
end
I am setting Time.zone for each user in a before filter in the application controller, and then calling the display_time method:
def my_before_filter
Time.zone = current_user.time_zone
current_user.display_time
end
I am also setting Time.zone for each user in a loop in my rake task (an hourly cron job), and then calling the same method:
Users.all.each do |user|
Time.zone = user.time_zone
user.display_time
end
How can I ensure that the two time zone settings will not interfere with each other ?
I want the display_time method to always use the Time.zone set via the application controller, except when it is called from the cron task’s loop. How can I achieve this ?
Thanks in advance!
Make display_time take the time parameter.
From your rake task, send the
current_timethat you want.