Sessions

Hi there guys!

I’m having problems with sessions. Ive created a sessions table via the
db:sessions:create. Now what happens is that whenever i
maneuver around my site, it keeps on creating new sessions. I just want
one session per user to store their user ids. I was just wondering
where i was going wrong.

thanks!

come on lads! you gotta help me! cry…

Maybe you could provide some code to help us better understand what you
are doing. My app, for example, creates a session variable when a user
logs in or creates an account like so:

session[:user] = User.authenticate(params[:current_user][:emailaddr],
params[:current_user][:password]).id

Then it gets destroyed when they leave.

Do you have some kind of before_filter in your model that keeps hitting
that part of the code that makes the session variable? This would result
in a session variable continiously being created.

For example, to ensure that a user is who they say they are when they
try to navigate to a certain page in my app, I have apllied a filter
that does a check before they can view that page:

before_filter :check_authentication, :except => [. . . .]

Do you have something similiar that makes use of a filter and then
creates a session variable?

Good luck,

-S

Thanks for replying Shandy!

Im a bit of a noob! I dont have any filters yet! Do i need to?

To use sessions and the session hash all you need to do is create a
session variable like so:
session[:key_name] = …

Everything else is automatic, at least if you haven’t touched the
original Rails settings.

You don’t need to use filters to use sessions, but for user
authentication for example it is probably a good idea.

Regards

Erik L.

On 12 Nov, 23:53, Serkan S. [email protected]