I’m writing a feature for my rails app whereby for any arbitrary action that requires a user to be logged in, a not-logged-in user will be prompted with an ajax modal to register/login first, and after registration/login, the original action is completed.
I’m trying to store the information about the original action in a session. However, the session data is disappearing when I try to access it at the end of registration/login.
When I detect an “anonymous” user, I save info about the action:
session[:interrupted_action] = #info on original action
Then render the signup/login modal.
After that is complete, I try to access the session info again:
if session[:interrupted_action]
#do stuff to complete action
Unfortunately, session[:interrupted_action] is now nil. I feel like I’m missing some obvious gotcha with sessions, but I haven’t been able to figure it out yet.
What should I be doing/investigating here?
From Rails guides
config.session_store is usually set up in config/initializers/session_store.rb and specifies what class to use to store the session. Possible values are :cookie_store which is the default, :mem_cache_store, and :disabled. The last one tells Rails not to deal with sessions. Custom session stores can also be specified.
So if you are using the default configuration, the session is stored in cookies. Make sure your browser allows cookies to be stored.
You can check if there are any entries in the cookies for your localhost
Also, try printing the session itself to see if there is anything in the hash.