Session variables

Is there a way to concatenate a number onto a string and use that string
in a session variable? I tried something like…

x = 1
session[“user” + x] = user one

but nothing happen unless I use the session[:user] syntax. Is there a
way around this so I can set the session[:user + x] variable?

Thanks in advance

Chris H. wrote:

session[“user#{x}”.to_sym]

FYI, it’s generally not recommended to store whole objects in the
session. It’s much better to store just the ID and retrieve the object
from the database when you need it.

session[:user_id] = @user.id

then in future page views

User.find(session[:user_id])


http://www.5valleys.com/
http://www.workingwithrails.com/person/8078

FYI, it’s generally not recommended to store whole objects in the
session. It’s much better to store just the ID and retrieve the object
from the database when you need it.

Thanks a lot. I am not using it for a whole object. I tried to make
the example as simple as possible. Thanks for the advice though.