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:incompute’
#{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”}

your method is static
but
session is an instance-bound method

change this

def ApplicationController.chosen_thing

to

def chosen_thing

Donald B. schrieb:

Hi Donald,

You should not be using ApplicationController as either a controller
name or
as a method name.

hth,
Bill