I want to make each of the time stamps on my ruby application according to the user selected time zone. I am new to ruby in rails so can’t figure out how to do it.
I made drop down list appear for the user to select timezone from through
<%= time_zone_select( "user", 'time_zone', ActiveSupport::TimeZone.all, :default => "Beijing")%>
How to make the choice of time zone reflect on all the time stamps used.
using a
before_filterinapplication_controller.rbmakes sure that this method is called every request. The default timezone on every request is set byconfig.time_zoneso you have to updateTime.zoneon every request. look at http://api.rubyonrails.org/classes/Time.htmlto evaluate an expression using a particular timezone, use
Time.use_zoneUPDATE: using
sessionto save the timezone