Rails 3 how to get new session id
Background - I execute reset_session
before the new user logs in, but I also want to associate certain data with the user session, so I identify each session with session_id
. I wanted to do this after successfully logging in through some kind before_filter
that checks every request, but reset_session
no new one is created after running rails session_id
.
Does anyone know how to generate a new session with session_id after being executed reset_session
in the same request?
> session.class
=> Rack::Session::Abstract::SessionHash
> session[:session_id]
=> "01aa3b8e7c7c26ab82b7a57e2b0f749b"
> reset_session
=> nil
> session.class
=> Hash
> session[:session_id]
=> nil
I saw a post that said it was a bug, but he was 3 years old and did not mention any way to get a new session ID other than making another request.
> tmp = session.dup
=> {"session_id"=>"01aa3b8e7c7c26ab82b7a57e2b0f749b", ...}
> reset_session
=> nil
> session.replace(tmp)
=> {"session_id"=>"01aa3b8e7c7c26ab82b7a57e2b0f749b", ...}
> session[:session_id]
=> nil
Some other people have also mentioned duplicating a session and replacing it, but that doesn't create a new one session_id
either
source to share
No one has answered this question yet
Check out similar questions: