Login Session Data Not Persisting In Rails 6

泄露秘密 提交于 2020-12-27 07:25:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!