session madness *argh*

Environment: Rails 2.0.2; cookie-based sessions (as far as I know... I added the two appropriate lines to environment.rb)

Problem: I'm getting inconsistent results storing things in the session.

For example, I create a data structure like this: people = [["bob",133] ["joe",145]] Then I set session[:people] = people

I've got sections of my current page with some JavaScript elements (YUI DataTables) that, based on some user actions, generate new requests to my controller.

In my actions in the controller, I'm expecting session[:people] to be valid (because I initialized it with people as described above). However, I'm seeing inconsistent behaviors with that session. Some data is persisting from one call to the next, but others are not.

My session itself isn't being cleared or reset, because if it were I'd lose my "authentication" and be redirected to my login page.

Any suggestions?

Environment: Rails 2.0.2; cookie-based sessions (as far as I know... I added the two appropriate lines to environment.rb)

Problem: I'm getting inconsistent results storing things in the session.

For example, I create a data structure like this: people = [["bob", 133] ["joe",145]] Then I set session[:people] = people

I've got sections of my current page with some JavaScript elements (YUI DataTables) that, based on some user actions, generate new requests to my controller.

Do you ever have concurrent requests? The following can happen

request 1 loads session request 2 loads session request 2 sets session[:people] request 2 saves session (ie sends the cookie back to the user in the
case of the session store request 1 saves session

Request 1 never knew about the changes made by request 2 and will
happily stomp all over the changes made by request 2. I wrote this up
in more detail a while ago (钛刻专家——官网 )

Fred

Oh wow, I didn't realize that's how it would work underneath. That could be my problem.

My page is creating a dozen divs, each of which contains a YUI DataTable, and each of which makes its own (concurrent) request to the controller for data (which I'm rendering out as XML to feed into the DataTable). It's not my choice to make something this complex, but that aspect is beyond my control.

There are multiple requests to my controller->action going on.

Forgive my confusion here, but my prior experience is with Java (Servlet/JSP) sessions. My assumption here was that by saying session[:something] = x, that would go into memory on the server and persist until I explicitly reset the session or some session timeout occurred. My Googling on Rails sessions hasn't led me to what I feel is a complete, definitive document on the subject. I'd love if someone had a good reference for me.

Thanks, Michael

Oh wow, I didn't realize that's how it would work underneath. That could be my problem.

My page is creating a dozen divs, each of which contains a YUI DataTable, and each of which makes its own (concurrent) request to the controller for data (which I'm rendering out as XML to feed into the DataTable). It's not my choice to make something this complex, but that aspect is beyond my control.

Sounds like it could be your problem.

There are multiple requests to my controller->action going on.

Forgive my confusion here, but my prior experience is with Java (Servlet/JSP) sessions. My assumption here was that by saying session[:something] = x, that would go into memory on the server and persist until I explicitly reset the session or some session timeout occurred. My Googling on Rails sessions hasn't led me to what I feel is a complete, definitive document on the subject. I'd love if someone had a good reference for me.

There are several session stores in rails, the default is the cookie
store. With all the other stores, your session cookie just contains
some unique identifier which enables rails to locate the correct file/ database row/ memcache entry etc... With the cookie store the entirety
of the session is stored in the cookie. But apart from that what you say about sessions is basically true.
What is unfortunate is the behaviour when there are multiple requests
from the same user. the situation could probably be improved creating sessions on demand
and only writing them back if the session has changed (there's a
ticket proposing this and other changes be made #92 [FEATURE] More efficient session handling - Ruby on Rails - rails   )

Fred