问题
I am implementing a user authentication system in Ruby on Rails following this tutorial Building a Simple Session Based Authentication using Ruby on Rails.
I think I did everything as explained in the article, but I could not get the user_id to be persisted across page refresh after a successful login.
This is the log_in method
def log_in(user)
session[:user_id] = user.id
end
After I successfully logged in, I checked if the user id was saved in the session by printing out p session[:user_id] it returns nil
回答1:
After spending the day trying out various suggestions from others, I finally discovered that my browser was actually blocking the session from persisting.
I changed my browser to another one and everything worked like magic.
来源:https://stackoverflow.com/questions/65355944/login-session-data-not-persisting-in-rails-6