Transferring a session from an active record store to a cookie store

Rails 4 will include cookie-based encrypted sessions. We would like to switch to this from the active cookie storage. Is there a way to do this without interrupting the clients of my application? I do not want to delete all current sessions.

+4
source share
3 answers

Agree with Nathan, do not go back if you are not worried about database performance due to session storage. In this case, I suggest Redis or Memcached store for your sessions, not cookies.

+2
source

There is one more problem. I tried to switch from the active record to the cookie store, and every user now gets the error "We're sorry, but something went wrong." The solution is to clear the cookies, but I have to tell every user about it. Many of them will think that the site is broken. So this is bad. And if you canโ€™t contact each user, this is very bad.

0
source

This is doable, I just did it differently (for reasons that I wonโ€™t go into, we needed to have them in the database). In the application controller, set the filter before as follows:

prepend_before_filter :migrate_session def migrate_session # migrating over old sessions session_model = YourSessionModel.find_by_session_id(session.id) if session_model data = session_model.data data.each do |key,value| session[key] = value end session_model.destroy end end 

Everything in the session hash will be stored in a cookie. After you no longer have active recording sessions, you can get rid of this code.

0
source

Source: https://habr.com/ru/post/1480563/


All Articles