When I try to set a session variable, in ApplicationController, I get this: NoMethodError in ManagementController#index You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] RAILS_ROOT: c:/dev/qna Application Trace | Framework Trace | Full Trace c:/dev/qna/app/controllers/application_controller.rb:10 c:/dev/qna/app/controllers/management_controller.rb:1 The code is below class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details session[:current_user_id] = "546" end Why I cannot set the session varaible?
rtacconi wrote:> When I try to set a session variable, in ApplicationController, I get > this: > > NoMethodError in ManagementController#index > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[]> > RAILS_ROOT: c:/dev/qna > Application Trace | Framework Trace | Full Trace > > c:/dev/qna/app/controllers/application_controller.rb:10 > c:/dev/qna/app/controllers/management_controller.rb:1 > > The code is below > > class ApplicationController < ActionController::Base > helper :all # include all helpers, all the time > protect_from_forgery # See > ActionController::RequestForgeryProtection for details > session[:current_user_id] = "546" > end >Really? That''s only about 5 lines of code and the error is being reported on line 10. What''s on line 10?> Why I cannot set the session varaible?Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
On Oct 21, 5:49 pm, rtacconi <rtacc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When I try to set a session variable, in ApplicationController, I get > this: > > NoMethodError in ManagementController#index > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[]> > RAILS_ROOT: c:/dev/qna > Application Trace | Framework Trace | Full Trace > > c:/dev/qna/app/controllers/application_controller.rb:10 > c:/dev/qna/app/controllers/management_controller.rb:1 > > The code is below > > class ApplicationController < ActionController::Base > helper :all # include all helpers, all the time > protect_from_forgery # See > ActionController::RequestForgeryProtection for details > session[:current_user_id] = "546"This is executing when application controller loads, in the context of the class, (rather than an individual instance of it) which doesn''t make any sense. If you want to play with the session you need to be doing so from an instance method of a controller (since session itself is an instance method of controllers) Fred> end > > Why I cannot set the session varaible?