I'm trying to update ruby in our project to 2.5 and up, and bundler from 1.17.2
to 2.0.1
. After doing so, running our application produces the following error in multiple places:
FrozenError - can't modify frozen String:
This is a result of trying to set the timezone in a controller (Time.zone = current_user.location.time_zone
) among other places.
You can use Time.use_zone(zone) with a block, for example:
class ApplicationController < ActionController::Base
around_action :set_time_zone
def set_time_zone
if logged_in?
Time.use_zone(current_user.location.time_zone) { yield }
else
yield
end
end
end
https://api.rubyonrails.org/classes/Time.html#method-c-zone-3D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With