`
CaiDeHen
  • 浏览: 89807 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#106 Time Zones in Rails 2.1

阅读更多
In the past, time zones have been very difficult to work with, but no longer! Rails 2.1 brings with it great time zone support as you can see in this episode.

rake time:zones:local

# config/environment.rb
config.time_zone = "Pacific Time (US & Canada)"

# controllers/application.rb
before_filter :set_user_time_zone

private

def set_user_time_zone
  Time.zone = current_user.time_zone if logged_in?
end

# in migration file
add_column :users, :time_zone, :string

<!-- users/new.html.erb -->
<%= f.time_zone_select :time_zone, TimeZone.us_zones %>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics