How to handle time zone conversion implementing ActiveSupport in Ruby on Rails 7.1?
After trying multiple solutions online, I still can't figure this out. I'm working with an scenario with time zone conversions using ActiveSupport in Ruby on Rails 7.1. My application stores timestamps in UTC, but when I retrieve them, they don't seem to convert to the user's local time correctly. I'm using the following code to set the time zone based on user preferences: ```ruby class ApplicationController < ActionController::Base before_action :set_time_zone private def set_time_zone Time.zone = current_user.time_zone if user_signed_in? end end ``` However, when I try to display timestamps, such as when rendering a user's last login: ```ruby <%= current_user.last_sign_in_at.strftime('%Y-%m-%d %H:%M:%S') %> ``` The output is still in UTC, and I get a time of something like `2023-10-15 10:00:00` instead of the expected `2023-10-15 03:00:00` for a user in 'America/New_York'. I also tried using `in_time_zone` directly: ```ruby <%= current_user.last_sign_in_at.in_time_zone(current_user.time_zone).strftime('%Y-%m-%d %H:%M:%S') %> ``` But it still shows the same UTC time. I've double-checked that `current_user.time_zone` returns the expected string, like 'America/New_York'. Am I missing something in the configuration or is there something wrong with how I'm converting the time? Any help would be appreciated! Any ideas what could be causing this? How would you solve this? This is happening in both development and production on macOS. Any ideas what could be causing this?