我正在尝试将我们项目中的 ruby 更新到 2.5 及更高版本,以及来自 1.17.2
的 bundler至 2.0.1
.这样做之后,运行我们的应用程序会在多个地方产生以下错误:
FrozenError - can't modify frozen String:
这是尝试在 Controller (
Time.zone = current_user.location.time_zone
) 等其他地方设置时区的结果。
最佳答案
您可以将 Time.use_zone(zone) 与块一起使用,例如:
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
关于ruby-on-rails - FrozenError - 无法修改卡住字符串(ruby 2.5+),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55816046/