I''ve got a javascript that provides me with the timezone for the client. I want to use this to set Time.zone so that all my times stored in the database are displayed in the timezone for the client. So really simplistically var timezone = jstz.determine_timezone().timezone Time.zone = timezone.olson_tz obviously this can''t be done. I''ve taken a look on the web and can only find ''solutions'' over two years old and as ROR moves so fast I thought someone may know of a better solution. So can anyone suggest a simple solution? Many thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Ben, On Wed, Jul 13, 2011 at 9:47 AM, Ben Perry <b3nperry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve got a javascript that provides me with the timezone for the > client. I want to use this to set Time.zone so that all my times > stored in the database are displayed in the timezone for the client. > So really simplistically > > var timezone = jstz.determine_timezone().timezone > Time.zone = timezone.olson_tz > > obviously this can''t be done. I''ve taken a look on the web and can > only find ''solutions'' over two years old and as ROR moves so fast I > thought someone may know of a better solution. So can anyone suggest a > simple solution?It needs to be set on the server. You could do an AJAX call. HTH, Bill -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 13, 2011, at 10:53 AM, Bill Walton wrote:> Hi Ben, > > On Wed, Jul 13, 2011 at 9:47 AM, Ben Perry <b3nperry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I''ve got a javascript that provides me with the timezone for the >> client. I want to use this to set Time.zone so that all my times >> stored in the database are displayed in the timezone for the client. >> So really simplistically >> >> var timezone = jstz.determine_timezone().timezone >> Time.zone = timezone.olson_tz >> >> obviously this can''t be done. I''ve taken a look on the web and can >> only find ''solutions'' over two years old and as ROR moves so fast I >> thought someone may know of a better solution. So can anyone >> suggest a >> simple solution? > > It needs to be set on the server. You could do an AJAX call.Or, you could do this all in JavaScript, and simply translate the dates in the browser. Store -- and display -- one time zone, like UTC. But then on the client, collect all your dates (wrap them in a span.date or something that you can get using JS) and use the client''s notion of the time zone to adjust their display on screen. $$(''span.date'').each(function(elm){ var d = new Date(); var offset = d.getTimeZoneOffset() * 3600 * 1000; var adjusted = new Date(elm.innerHTML); adjusted.setTime(adjusted.getTime() + offset); elm.update(adjusted.toLocaleDateString()); }); Walter> > HTH, > Bill > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for the replies. The solution I''ve come up with for now is to use the javascript that determines the timezone to store the timezone in a cookie using the onload event. I then read it back out of the cookie in Rails with a before_filter on application_controller.rb. I''m not convinced its the best solution as obviously not everyone turns cookies on, hmmm... detect_timezone.js : jstz.set_timezone_in_cookie = function () { var tz_info = jstz.determine_timezone(); document.cookie="timezone =" + tz_info.timezone.olson_tz; } application_controller.rb : before_filter :set_timezone def set_timezone Time.zone = request.cookies["timezone"] end Any thoughts? Many thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You could do it with AJAX as well and store it in a session variable... # routes.rb post "timezone/set" # timezone_controller.rb def set session[:timezone] = params[:timezone] end # application_controller.rb before_filter :set_timezone def set_timezone Time.zone = session[:timezone] end # detect_timezone.js $.post("/timezone/set", { timezone: jstz.determine_timezone().timezone.olson_tz } ); -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Cn3QsKz_pBAJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''m very close but need a little help as my timezone controller set function isn''t being called. I can see the post call being made in the console and I can see before a filter being run on the timezone controller, but no set function. #routes.rb scope ''planbadmin'' do resources :timezone do member do post :set end end end # timezone_controller.rb class TimezoneController < ApplicationController def set ldb("setting timezone = ''#{params[:timezone]}''") #debug output session[:timezone] = params[:timezone] end end # application_controller.rb before_filter :set_timezone def set_timezone ldb("setting timezone #{session[:timezone]}") #debug output Time.zone = session[:timezone] end # detect_timezone.js jstz.set_timezone_in_session = function () { //prototype new Ajax.Request("/planbadmin/timezone/set", {parameters: { timezone:jstz.determine_timezone().timezone.olson_tz }} ); } onload = jstz.set_timezone_in_session(); #console output Started POST "/planbadmin/timezone/set" for 127.0.0.1 at 2011-07-14 09:38:13 +01 00 Processing by TimezoneController#set as JS Parameters: {"timezone"=>"Europe/London"} ←[1m←[36mUser Load (117.0ms)←[0m ←[1mSELECT TOP (1) [users].* FROM [users] WH ERE ([users].[userid] = N''benp'')←[0m Redirected to http://localhost/planbadmin/planb Completed 302 Found in 140ms Started GET "/planbadmin/planb" for 127.0.0.1 at 2011-07-14 09:38:13 +0100 Processing by PlanbController#index as HTML ===> C:/Projects/PLANB/interface/1.5.5/app/controllers/ application_controller.rb :68:in `set_timezone'': setting timezone = '''' Rendered planb/index.html.erb within layouts/application (5.0ms) Completed 200 OK in 35ms (Views: 35.0ms | ActiveRecord: 0.0ms) Many thanks On Jul 13, 5:30 pm, Tim Shaffer <timshaf...-BUHhN+a2lJ4@public.gmane.org> wrote:> You could do it with AJAX as well and store it in a session variable... > > # routes.rb > post "timezone/set" > > # timezone_controller.rb > def set > session[:timezone] = params[:timezone] > end > > # application_controller.rb > before_filter :set_timezone > def set_timezone > Time.zone = session[:timezone] > end > > # detect_timezone.js > $.post("/timezone/set", { timezone: > jstz.determine_timezone().timezone.olson_tz } );-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
#routes.rb scope ''planbadmin'' do resources :timezone do member do post :set end end end That''s your problem there. By putting the "set" method under member, it''s expecting it to be called for a timezone such as "/timezone/:id/set" If you''re going to set it up as a resource in routes, you probably want to use "collection" instead of "member" so it can be accessed via "/timezone/set" You can run "rake routes" from the command line and you can see what it is expecting. Of course the other option is just to add this one line to your routes instead of the resources snippet above: post "timezone/set" -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Npun_cjsYuAJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hmm, so I''ve updated the routes #routes.rb scope ''planbadmin'' do ... #removed the timezone resource end post "timezone/set" and the rake routes output is now timezone_set POST /timezone/set(.:format) {:controller=>"timezone", :action=>"set"} the console output is still exactly the same and the timezone set function still isn''t being called. Have you any other pointers? Again thanks for your help with this its very much appreciated. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
OK finally cracked it. Problem was with filters being run first in application_controller.rb. The timezone_controller.rb set function was being ignored as result of them. So #routes.rb scope ''planbadmin'' do resources :timezone do collection do post :set end end end #timezone_controller.rb class TimezoneController < ApplicationController skip_before_filter :admin, :authorise def set session[:timezone] = params[:timezone] redirect_to(:controller => "planb") end end Just a quick one, if I don''t have that redirect it barfs about a missing template. Is there a neat way around it? Thanks VERY much for all the help. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You can use "render :nothing => true" instead -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/E7glokNtpDcJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello friends, On Thu, Jul 14, 2011 at 9:15 PM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:> You can use "render :nothing => true" instead > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/E7glokNtpDcJ. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello friends, I am trying to get timezone in browser produce below error. jstz is not defined jstz.set_timezone_in_session = function () { My code: jstz.set_timezone_in_session = function () { $.post("/timezone/set", { timezone: jstz.determine_timezone().timezone.olson_tz } ); } onload = jstz.set_timezone_in_session(); I am using JQuery. If any one known about this suggestion me. Thanks, Dhamodharan.N> > > On Thu, Jul 14, 2011 at 9:15 PM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote: > >> You can use "render :nothing => true" instead >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/E7glokNtpDcJ. >> >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello friends, I forgot to download https://bitbucket.org/pellepim/jstimezonedetect/downloadsdetect_timezone.js. On Sat, Jul 16, 2011 at 2:22 PM, DHAMODHARAN N <dhamsoft-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello friends, > > I am trying to get timezone in browser produce below error. > jstz is not defined > jstz.set_timezone_in_session = function () { > > My code: > > > jstz.set_timezone_in_session = function () { > $.post("/timezone/set", { timezone: > jstz.determine_timezone().timezone.olson_tz } ); > } > onload = jstz.set_timezone_in_session(); > > I am using JQuery. > > If any one known about this suggestion me. > > Thanks, > Dhamodharan.N > > >> >> >> On Thu, Jul 14, 2011 at 9:15 PM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote: >> >>> You can use "render :nothing => true" instead >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Ruby on Rails: Talk" group. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/rubyonrails-talk/-/E7glokNtpDcJ. >>> >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> >> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Are you sure you''re using the latest version of the detect_timezone.js? When I was working on this I downloaded another older version that didn''t define the class jstz namespace. On Jul 16, 10:05 am, DHAMODHARAN N <dhams...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello friends, > > I forgot to downloadhttps://bitbucket.org/pellepim/jstimezonedetect/downloadsdetect_timez.... > > > > > > > > On Sat, Jul 16, 2011 at 2:22 PM, DHAMODHARAN N <dhams...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello friends, > > > I am trying to get timezone in browser produce below error. > > jstz is not defined > > jstz.set_timezone_in_session = function () { > > > My code: > > > jstz.set_timezone_in_session = function () { > > $.post("/timezone/set", { timezone: > > jstz.determine_timezone().timezone.olson_tz } ); > > } > > onload = jstz.set_timezone_in_session(); > > > I am using JQuery. > > > If any one known about this suggestion me. > > > Thanks, > > Dhamodharan.N > > >> On Thu, Jul 14, 2011 at 9:15 PM, Tim Shaffer <timshaf...-BUHhN+a2lJ4@public.gmane.org> wrote: > > >>> You can use "render :nothing => true" instead > > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "Ruby on Rails: Talk" group. > >>> To view this discussion on the web visit > >>>https://groups.google.com/d/msg/rubyonrails-talk/-/E7glokNtpDcJ. > > >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > >>> To unsubscribe from this group, send email to > >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >>> For more options, visit this group at > >>>http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello Ben Perry, I download js from https://bitbucket.org/pellepim/jstimezonedetect/get/tip.zip On Sat, Jul 16, 2011 at 8:24 PM, Ben Perry <b3nperry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Are you sure you''re using the latest version of the > detect_timezone.js? When I was working on this I downloaded another > older version that didn''t define the class jstz namespace. > > On Jul 16, 10:05 am, DHAMODHARAN N <dhams...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello friends, > > > > I forgot to downloadhttps:// > bitbucket.org/pellepim/jstimezonedetect/downloadsdetect_timez.... > > > > > > > > > > > > > > > > On Sat, Jul 16, 2011 at 2:22 PM, DHAMODHARAN N <dhams...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Hello friends, > > > > > I am trying to get timezone in browser produce below error. > > > jstz is not defined > > > jstz.set_timezone_in_session = function () { > > > > > My code: > > > > > jstz.set_timezone_in_session = function () { > > > $.post("/timezone/set", { timezone: > > > jstz.determine_timezone().timezone.olson_tz } ); > > > } > > > onload = jstz.set_timezone_in_session(); > > > > > I am using JQuery. > > > > > If any one known about this suggestion me. > > > > > Thanks, > > > Dhamodharan.N > > > > >> On Thu, Jul 14, 2011 at 9:15 PM, Tim Shaffer <timshaf...-BUHhN+a2lJ4@public.gmane.org> > wrote: > > > > >>> You can use "render :nothing => true" instead > > > > >>> -- > > >>> You received this message because you are subscribed to the Google > Groups > > >>> "Ruby on Rails: Talk" group. > > >>> To view this discussion on the web visit > > >>>https://groups.google.com/d/msg/rubyonrails-talk/-/E7glokNtpDcJ. > > > > >>> To post to this group, send email to > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >>> To unsubscribe from this group, send email to > > >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >>> For more options, visit this group at > > >>>http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maybe Matching Threads
- Mongrel starting Error
- [PATCH 0/3] Timezone and keyboard layout settings in virt-builder and virt-sysprep.
- using restful_authentication current_user inside controller specs
- [PATCH] add --truncate to virt-customize
- [PATCH] customize: add --truncate-recursive option