Donald Brady
2006-Jun-18 07:12 UTC
[Rails] Why can''t I use a session? (Symbol as array index)
Hi All I can''t for the life of me see what is wrong with this. Maybe it''s cause it''s midnight... I want to put some data in a session and I have some code like this: class ApplicationController < ActionController::Base model :mything def ApplicationController.chosen_thing session[:chosen_thing] ||= MyThing.defaultThing end end So whenever I try to access ApplicationController.mything in one of the controller subclasses I get the error below. Any help much appreciated. Donald TypeError in MainController#index Symbol as array index RAILS_ROOT: /Rails/foo/public/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/controllers/application.rb:10:in `[]'' #{RAILS_ROOT}/app/controllers/application.rb:10:in `compute'' #{RAILS_ROOT}/app/controllers/main_controller.rb:4:in `index'' Request Parameters: None Show session dump --- flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} -- Posted via http://www.ruby-forum.com/.
your method is _static_ but session is an instance-bound method change this def ApplicationController.chosen_thing to def chosen_thing Donald Brady schrieb:> Hi All > > I can''t for the life of me see what is wrong with this. Maybe it''s cause > it''s midnight... > > I want to put some data in a session and I have some code like this: > > class ApplicationController < ActionController::Base > > model :mything > > def ApplicationController.chosen_thing > > session[:chosen_thing] ||= MyThing.defaultThing > > end > > end > > So whenever I try to access ApplicationController.mything in one of the > controller subclasses I get the error below. > > Any help much appreciated. > > Donald > > TypeError in MainController#index > > Symbol as array index > RAILS_ROOT: /Rails/foo/public/../config/.. > > Application Trace | Framework Trace | Full Trace > #{RAILS_ROOT}/app/controllers/application.rb:10:in `[]'' > #{RAILS_ROOT}/app/controllers/application.rb:10:in `compute'' > #{RAILS_ROOT}/app/controllers/main_controller.rb:4:in `index'' > Request > > Parameters: None > > Show session dump > > --- > flash: !map:ActionController::Flash::FlashHash {} > > Response > > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > >