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 に答える