Getting Session ID

I thought I understood how to grab the session id but in the following
code I am getting null for the session id:

@foo = Foo.new(:session_id => session[:session_id],
:test_id => @test.id)

Will M. wrote:

I thought I understood how to grab the session id but in the following
code I am getting null for the session id:

@foo = Foo.new(:session_id => session[:session_id],
:test_id => @test.id)

I am closer I believe:

@foo = Foo.new(:session_id => session.id], :test_id => @test.id)

Now the problem is that the session id I am getting is not what I
expect:

Processing . . . [POST]
Session ID: d3aa0519df929116ea8e63cb353a1982
INSERT INTO foo (test_id, session_id) VALUES(1, 30652084)

The session ids do not match.

Will M. wrote:
[…]

I am closer I believe:

@foo = Foo.new(:session_id => session.id], :test_id => @test.id)

Now the problem is that the session id I am getting is not what I
expect:

Processing . . . [POST]
Session ID: d3aa0519df929116ea8e63cb353a1982
INSERT INTO foo (test_id, session_id) VALUES(1, 30652084)

The session ids do not match.

The session isn’t an AR instance so you’re getting Ruby’s Object#id
method which isn’t what you want.

I believe that session is an instance of CGI::Session so you probably
really want session.session_id instead.

Everything else aside… why on earth are you trying to capture the
session id? Rails is handling the user sessions for you, all you need
to do is work with the session object in your controllers and views.
I honestly can’t think of a single reason why I would want to grab a
session id and then put it into one of my own tables…

-Brian

On Apr 29, 2006, at 5:57 PM, Mike F. wrote:

Processing . . . [POST]
Session ID: d3aa0519df929116ea8e63cb353a1982
INSERT INTO foo (test_id, session_id) VALUES(1, 30652084)

The session ids do not match.

The session isn’t an AR instance so you’re getting Ruby’s Object#id
method which isn’t what you want.

I believe that session is an instance of CGI::Session so you probably
really want session.session_id instead.

I’m not sure what the de-facto-standard is here… but I typically
treat the session object as if it were a magical hash.

session[:session_id]… just like you’d do with params, cookies, and
flash.

@foo = Foo.new( :session_id => session[:session_id], :test_id =>
@test.id )

Cheers,

Robby

Robby R.
Founder & Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]

On Apr 29, 2006, at 5:57 PM, Mike F. wrote:

Processing . . . [POST]
Session ID: d3aa0519df929116ea8e63cb353a1982
INSERT INTO foo (test_id, session_id) VALUES(1, 30652084)

The session ids do not match.

The session isn’t an AR instance so you’re getting Ruby’s Object#id
method which isn’t what you want.

I believe that session is an instance of CGI::Session so you probably
really want session.session_id instead.

I’m not sure what the de-facto-standard is here… but I typically
treat the session object as if it were a magical hash.

session[:session_id]… just like you’d do with params, cookies, and
flash.

@foo = Foo.new( :session_id => session[:session_id], :test_id =>
@test.id )

Cheers,

Robby

Robby R.
Founder & Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]