Forum: Ruby on Rails newbie alert! diff between @session['user'].id and @session

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
newtorails. (Guest)
on 2007-01-26 02:23
(Received via mailing list)
I struggled for sometime to use @session[:user].id while using
LoginGenerator to retrieve id of the logged in user. In the end I could
make it work with @session['user'].id. Shouldn't the two approaches be

Conrad T. (Guest)
on 2007-01-26 03:17
(Received via mailing list)
Hi, you should be able to use script console to determine if they are
equivalent.  For example,

irb(main):001:0> a = {}
=> {}
irb(main):002:0> a[:this] = 'foo'
=> "foo"
irb(main):003:0> a[:this]
=> "foo"
irb(main):004:0> a['this'] = 'foo2'
=> "foo2"
irb(main):005:0> a[:this]
=> "foo"
irb(main):006:0> a[:this] == a['this']
=> false

Good luck,

newtorails. (Guest)
on 2007-01-26 03:28
(Received via mailing list)
Ok, makes sense.. Thanks..
i think loginGenerator by default generates the code that use quotes
for array reference.
Rob S. (Guest)
on 2007-01-26 04:53
(Received via mailing list)
Actually, this may be misleading in the case of session, params, and
other certain 'special' hashes that Rails uses.  Rails has a
"HashWithIndifferentAccess" that allows accesing something by symbol
_and_ key, so that session[:foo] == session['foo'].  I'm not positive
that session uses that hash, but you should test this right in a
controller and not just in a plain irb session.

- Rob
Matt J. (Guest)
on 2007-01-26 05:20
(Received via mailing list)
A note: accessing the session with @session[] has been deprecated for
a while now
(a few months). Try using just 'session[:user]'.


On 1/25/07, newtorails. <removed_email_address@domain.invalid> wrote:
Matt J.
President/Technical Director, Acme Art Company (
Conrad T. (Guest)
on 2007-01-26 15:09
(Received via mailing list)
Hi, my test using IRB was consistent with my test using sessions
within a controller.  Thus, the following isn't equal:

session[:user] != session['user']

In general, they implemented session as global hash within Rails.

newtorails. (Guest)
on 2007-01-26 21:12
(Received via mailing list)
Matt, changing @session to session[..] doesn't change the situation..
let me know if you see anything different.
This topic is locked and can not be replied to.