It requires installation of tztime and tzinfo_timezone plugins. I seem
to have successfully installed these plugins and they appear in my
vendor/plugins directory. I’ve tried to use this plugin in my
application the way the tutorial recommends:
class ApplicationController < ActionController::Base
around_filter :set_timezone
private
def set_timezone
TzTime.zone = current_user.tz
yield
TzTime.reset!
end
end
But I get the error: “uninitialized constant
ApplicationController::TzTime” on the “TzTime.zone =” line. Am I
skipping a step to install the tztime plugin? I don’t have to move
vendor/plugins/tztime/lib/tz_time.rb to app/models directory, do I?
TzTime.zone
=> #<TzinfoTimezone:0xb9d83e34 @utc_offset=-21600, @name=“Central Time
(US & Canada)”>
Do you get that output?
I have this in my config/environment.rb file:
Use tzinfo library to convert to and from the users timezone
gem ‘tzinfo’
include TZInfo
TzTime.zone = TimeZone[‘Central Time (US & Canada)’]
This makes Time.now return time in UTC
ENV[‘TZ’] = ‘UTC’
I get “nil” as a response to “TzTime” from console. When I put what you
have into my own environment.rb file, I get “NameError: uninitialized
constant TzTime from (irb):1” as a response.
I’m running rails on Locomotive on OSX if that makes any difference.
Ah, that was it. I even though I was able to install plugins from the
gem, my app somehow did not have access to the gem. Thanks so much for
helping me diagnose this issue Michael
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.