Application Controller Flashcards
1
Q
(APP) def current_user
A
@current_user ||= User.find_by(session_token: session[:session_token])
2
Q
(APP) def ensure_logged_in!
A
redirect_to new_session_url unless logged_in?
3
Q
(APP) def log_in!
A
def log_in!(user) session_token = user.reset_session_token! @current_user = user end
4
Q
(APP) def log_out!
A
current_user.reset_session_token!
session[:session_token] = nil
@current_user = nil
5
Q
(APP) def logged_in?
A
!!current_user