Understand “current_user” concept when creating a login session in ruby

后端 未结 2 2180
青春惊慌失措
青春惊慌失措 2021-02-10 17:36

I am going through the great Michael Hartl tutorial to build ruby app here.

I am trying to understand the concept of how to create a session and I am stuck in understand

2条回答
  •  你的背包
    2021-02-10 18:14

    The method def current_user=(user) is basically a setter that the sign_in method uses in order to set the current_user.

    def current_user will return the @current_user or if it is not set it will find it in the Users table by the remember_token. This basically allows you get the current_user at any point in time.

    self.current_user in the context of the sign_in method will refer to the calling class or module in this case. It will be calling current_user from the Session Helper module.

提交回复
热议问题