Newbie problem => sessions


i have a little problem, that i cant resolve.

how can i put in a session as an object? i mean, for example i know only
to give a value to a session so:

@session[‘something’] = “hello world”

but i want to give to the @session[‘something’] a name, an age, etc
so i can call the name of the session like:


i dont know which one the right syntax is.

thanks!! bye!

hey sabin,

@session[‘key’][‘value’] = 3
@session[‘key’][‘value2’] = 3.5
@session[‘key2’][‘someother-value’] = 4

this would result in the data you just entered like this:
(two seperate hashes)

‘key’ hash would look like this: {“value” => 3, “value2” => 3.5 }
and the
‘key2’ hash would look like this: {“someother-value” => 4 }

…if this isn’t helpful enough, i personally like; it’s
a great site. either way, i hope on of the two provides a good enough
solution to the problem.
good luck,


hey harper!

thanks for ur answer, but it doesnt work :S

i was checking the “login” generator, and there the script put different
values as i like in the session ‘user’.

ur syntax @sessionâ??[‘something’][‘vaue1’] = 100 doesnt work.

someone has an idea?? ty!

i’m not exactly sure of what you are trying to do in the big picture, so
i may be leading you to places you don’t need to go to (?) , but here’s
a shot in the dark, i hope it somewhat helps.

if you want to assign values to a @session[x][y] variable, (creating a
hash) you will first need to define that the @session[x] is of a Hash
so, to assign, say, 100 to @session[‘something’][‘vaue1’] you will first
need to define

@session[‘something’] =

and then

@session[‘something’][‘value1’] = 100

…if you check the contents of the session
((@session[‘something’].inspect)) you will see that it will give you:

{‘value1’ => 100}

(btw, if you are using the acl system from, and you
don’t want to erase the @session[‘user’] - - you just want to add more
data, make sure you put the BEFORE you the session is created.
(i.e, the user logs in)
so that doesn’t overwrite the current session.
i hope this helps. i know there are great reading materials in if i’m leading you round round and astray.


Hi Sabin,

sabin sur wrote:

how can i put in a session as an object?

There’s no magic here. The session will hold an object if you assign an
object to it.

@session[‘something’] = “hello world”

But if you keep using ‘@session’ you’re going to have problems. The
instance variable syntax has been depracated since 1.2. Use ‘session[]’
instead (drop the ‘@’)

but i want to give to the @session[‘something’]
a name, an age, etc

You need to create a model for your ‘something’ object that includes
attributes. Then assign that object to the session. The syntax you
to use should work, but I haven’t tested it…