Rails 3: setting the timezone to the current users timezone

前端 未结 3 1584
花落未央
花落未央 2020-12-03 00:00

I put this in Application Controller:

before_filter :set_timezone 

def set_timezone  
Time.zone = current_user.time_zone 
end  

But I alwa

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 00:38

    Max -- the ryandaigle.com article you mentioned links to this writeup where you need to create a migration to add "time_zone" as an attribute to the user

    (this is from the article, in rails 2.x syntax)

    $ script/generate scaffold User name:string time_zone:string
    $ rake db:migrate
    

    later

    <%= f.time_zone_select :time_zone, TimeZone.us_zones %>
    

    That's why your .time_zone is returning a method_missing -- you haven't stored the time_zone on the user yet.

提交回复
热议问题