Wednesday, March 21, 2007

When is a session not a session?

OK... this is strange. Rails maintains a session hash so that you can store your state.

In one part of my code, I write:
session['user_id'] = User.find_by_login(params['user_login']).id "Login! - /#{session['user_id']}/,/#{session['user_login']}/"

and that works just fine.

In part of another module (a plugin which works just fine before the change), I write:
@#{singular_name}.user_id = session['user_id']
and that fails with the error:
can't convert String into Integer
#{RAILS_ROOT}/vendor/plugins/ajax_scaffold_plugin-3.2.4/lib/ajax_scaffold_plugin.rb:283:in `[]'

Which says to me that it doesn't like 'user_id' as the key into the session hash, but it's acting as if it thinks session is suddenly an array...?

But... the session dump shows that it's there:
user: !ruby/object:User
id: "6"
password: 8b2f204be0bad5668fd1c89f8f25b5ea4106f057
login: rich
user_login: rich
user_id: 6
:page: "1"
:sort_direction: asc
flash: !map:ActionController::Flash::FlashHash {}

Must be something automagical...

No comments:

Post a Comment