Adam D. wrote:
Ray thanks for the help. If i understand you correctly, you can not
the cookies[:_session_id] cookie but instead I should
- set some other cookie with the user information in it, like user_id
- drop in a before_filter in the application.rb controller to check to
see if it exists,
Yes, that will work.
- load the session from the user_id found in this cookie
You could do that. It means you’ll have to store the session_id in the
user table, or if you are storing your sessions in the db you could have
a sessions_users table, or something similar. It depends on your
application and what aspects of the session state you are interested in
If there is only a small amount of data you want to store, it’s probably
easier to store it in a dedicated model that you could access by user or
in a cookie.
thanks for clearing that up, although i am still a little foggy as to
why i cant extend the life of the _session_id cookie that gets set by rails to
correspond to the session data that got created.
Short answer, ActionController sets the session cookie on every
response. You only set it once.
For illustration, I copied the cookie[_session_id] code from your
previous post into one of my controllers and then I hit the action in my
browser while following the action in LiveHTTPHeaders. Here are the
response headers that were returned to a request.
HTTP/1.x 200 OK
Set-Cookie: _session_id=a7563ea152685329ffebfd55149872d8; path=/;
expires=Sat, 28 Apr 2007 23:29:08 GMT
Set-Cookie: _session_id=a7563ea152685329ffebfd55149872d8; path=/
Date: Fri, 28 Apr 2006 23:29:08 GMT
You can see that the session cookie is set twice in immediate
succession. The first time your code sets it to expire in a year, the
second time, ActionController sets a cookie the same name that has no
expiration. The web browser overwrites your cookie with a second cookie
and since it has no expiration date, the browser assumes that the cookie
expires when the browser is closed.
ActionController sends this cookie in every response, overwriting
whatever you do.
Hope that helps.