new session records in DB don't get created until after "after_filter"s have run????


I’m using active record for sessions. I’m just noting that in terms of picking up the number of active users from the “session” table, that this works fine however it seems to MISS picking up one’s own active session for the situation when it is first access to the page (
i.e. it the request where your session gets created).

For example if I navigate to my site:

  • first hit: active users list don’t include me (as it seems the session record is not yet in the sessions table)???
  • subsequent hits to site: everything is then fine

Can anyone tell me how to ensure the newly created session is persisted to the database prior to the "before_filter"s running??
(i.e. I use a before filter to populate an instance variable with the list of active users, i…e from a query to the database)???


just tried putting a “redirect params” for these cases so that in these cases once the session is setup the browser is instructed to ask again :slight_smile: Not idea re response time re forcing another request from browser but it works and I’m not sure how else to handle this…???

Just my $.02, but I think you're overloading the session. You have users, so
marking their last activity datetime when they hit the site and offline if
they've been idle for some arbitrary amount of time might make more sense.
You could have a background job handle marking the users as inactive or do
it in one SQL update query.

Greg Hauptmann-3 wrote:

tks - I’m effectively doing this I think (if I interpret your suggestion correctly) - the minor implementation issue I have seems to be due to the way that rails “active record session” mechanism for storing session state work. It seems to only push the details of a new session to the database after the “before_filter” and “after_filter” points, so that means during a “before_filter” when I query the sessions table the new session isn’t in there yet.

Hope this makes sense? Wasn’t exactly sure what you meant re how to get around the above?