Created
January 22, 2016 23:07
-
-
Save jkarnowski/197bb2bd8fa9c4ca9c86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
helpers do | |
def login(user) | |
session[:id] = user.id | |
end | |
def logged_in? | |
session[:id] != nil | |
end | |
# ANOTHER APPROACH: | |
# current_user.present? | |
# !!current_user | |
def current_user | |
@user ||= User.find(session[:id]) if session[:id] | |
end | |
# ANOTHER APPROACH: | |
# @current_user ||= User.where(id: session[:id]).first | |
# clears just that session id | |
def logout! | |
session[:id] = nil | |
redirect '/' | |
end | |
end | |
# logout versus logout! | |
# ANOTHER APPROACH TO LOGOUT!: | |
# session.delete(:user_id) | |
# clears EVERYTHING | |
# session.clear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment