Skip to content

Instantly share code, notes, and snippets.

@rakibulislam
Created June 25, 2019 00:56
Show Gist options
  • Save rakibulislam/a987734329df8238cd2db4e77299dfd0 to your computer and use it in GitHub Desktop.
Save rakibulislam/a987734329df8238cd2db4e77299dfd0 to your computer and use it in GitHub Desktop.
# Here's an example of how you might set <tt>Time.zone</tt> on a per request basis and reset it when the request is done.
# <tt>current_user.time_zone</tt> just needs to return a string identifying the user's preferred time zone:
#
class ApplicationController < ActionController::Base
around_action :set_time_zone
def set_time_zone
if logged_in?
Time.use_zone(current_user.time_zone) { yield }
else
yield
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment