class ApplicationController < ActionController::Base
private
# Finds the User with the ID stored in the session with the key
# :current_user_id This is a common way to handle user login in
# a Rails application; logging in sets the session value and
# logging out removes it.
def current_user
@_current_user ||= session[:current_user_id] &&
User.find_by_id(session[:current_user_id])
end
end
How to understand the code above? What does ||=
mean? And is @_current_user
an id or a user object? Also, why it starts with _
?
Can anyone answer me what @_current_user
is?