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 <[email protected]> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.