0

I'm storing the Rails Sessions in database using Active Record Store. At some point I want to replace the actual Rails Session for another one extracted from the database.

Let's say the Session to restore ID comes in the param session_id.

How can I retrieve the Session to restore and replace the actual session?

4

1 回答 1

1

我发现最简单的方法是在 before_filter

def restore_session
  return if params[:session_id].blank?

  restored_session = ActiveRecord::SessionStore::Session.find_by_session_id(params[:session_id])
  if restored_session
    session.update(restored_session.data)
    restored_session.destroy
  end
end
于 2012-11-14T13:35:14.750 回答