Railsã¢ããªã§ã¦ã¼ã¶ã®ã¿ã¤ã ã¾ã¼ã³ãåå¾ããæ¹æ³
Railsã§ã¢ããªã±ã¼ã·ã§ã³ãä½æãã¦ãã¦ãã¦ã¼ã¶ã®ã¿ã¤ã ã¾ã¼ã³ãã¦ã¼ã¶ã®æããããããããã¨ç¡ãåå¾ããããã¨ãããããã®æ¹æ³ã調ã¹ããã®ã®ãã決ã¾ãã®æ¹æ³ããããã®ãè¦ã¤ãããã¨ãã§ããªãã£ãã
ããã§ã²ã¨ã¾ããdetect_timezone_railsã¨ããgemãå©ç¨ãã¦ãã©ã¦ã¶å´ã§ã¿ã¤ã ã¾ã¼ã³ãå¤å®ãã¦çµæãcookieã«ä¿åãããµã¼ãå´ã§ãã®å¤ãèªã¿åããã¨ã«ããã
Gemfile ã«æ¬¡ã®è¡ãå ¥ãã¦bundle installããã
gem 'detect_timezone_rails'
assets/javascripts/application.js ã«æ¬¡ã®è¡ã追è¨ããã
//= require detect_timezone //= require jquery.detect_timezone //= require jquery.cookie
jquery.cookie pluginã¯ãã¡ããã https://github.com/carhartl/jquery-cookie
assets/javascripts/timezone.js.coffee ã¨ãã£ãååã®ãã¡ã¤ã«ãä½ã£ã¦ä»¥ä¸ã®å 容ãæ¸ãã
$ -> unless $.cookie('timezone')? $.cookie('timezone', $("html").get_timezone(), {expires: 1})
app/controller/application_controller.rb ã«ã¿ã¤ã ã¾ã¼ã³ãè¨å®ããã³ã¼ããæ¸ãã
before_filter do Time.zone = cookies[:timezone] || 'UTC' end
ãã£ã¨ç°¡åãªæ¹æ³ãªãããªã