Last active
December 30, 2016 06:35
-
-
Save Carpetfizz/155184e661c8f8f083095a9c52f7c2cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ApplicationController < ActionController::Base | |
protect_from_forgery with: :exception | |
helper_method :current_user | |
def authenticate | |
redirect_to :login unless user_signed_in? | |
end | |
def current_user | |
@current_user ||= User.find(session[:user_id]) if session[:user_id] | |
end | |
def user_signed_in? | |
# converts current_user to a boolean by negating the negation | |
!!current_user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment