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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4ef13c377f2d1c9e907a73b92335a868?d=identicon&s=25 newtorails. (Guest)
on 2007-01-26 01: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
same?

thanks.
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2007-01-26 02: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,

-Conrad
4ef13c377f2d1c9e907a73b92335a868?d=identicon&s=25 newtorails. (Guest)
on 2007-01-26 02:28
(Received via mailing list)
Ok, makes sense.. Thanks..
i think loginGenerator by default generates the code that use quotes
for array reference.
Df5e7adb20adae6c120b04e7cafb15a0?d=identicon&s=25 Rob Sanheim (rsanheim)
on 2007-01-26 03: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
4858ffb014831b3741753920314adc90?d=identicon&s=25 Matt Jones (Guest)
on 2007-01-26 04: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]'.

--Matt

On 1/25/07, newtorails. <smangla@gmail.com> wrote:
>
--
Matt Jones
mdj.acme@gmail.com
President/Technical Director, Acme Art Company (acmeartco.org)
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2007-01-26 14: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.

-Conrad
4ef13c377f2d1c9e907a73b92335a868?d=identicon&s=25 newtorails. (Guest)
on 2007-01-26 20: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.