New session records in DB don't get created until after "aft


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
works fine however it seems to MISS picking up one’s own active session
the situation when it is first access to the page (i.e. it the request
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
the database prior to the "before_filter"s running?? (i.e. I use a
filter to populate an instance variable with the list of active users,
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
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
they’ve been idle for some arbitrary amount of time might make more
You could have a background job handle marking the users as inactive or
it in one SQL update query.

Greg H.-3 wrote:

record is not yet in the sessions table)???

View this message in context:'t-get-created-until-after-"after_filter"s-have-run-----tf2705243.html#a7545083
Sent from the RubyOnRails Users mailing list archive at

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
way that rails “active record session” mechanism for storing session
work. It seems to only push the details of a new session to the
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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs