I am following along with Michael Hartl's rails tutorial. I am confused with a portion of the sessions helper module.
In the following code can someone please clarify if the current_user in the logged_in? method refers to the actual method current_user and is read as the user is only logged_in? if the method current_user dies not return nil?
OR
Is the current_user referring to the instance variable @current_user inside of the current_user method
Any clarification is greatly appreciated. Thank you so much!
module SessionsHelper
# Logs in the given user.
def log_in(user)
session[:user_id] = user.id
end
# Returns the current logged-in user (if any).
def current_user
if session[:user_id]
@current_user ||= User.find_by(id: session[:user_id])
end
end
# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end
end
logged_in?means: The return value from thecurrent_usermethod is not (!)nil?.