Skip to content

Instantly share code, notes, and snippets.

@Carpetfizz
Last active December 30, 2016 06:35
Show Gist options
  • Save Carpetfizz/155184e661c8f8f083095a9c52f7c2cd to your computer and use it in GitHub Desktop.
Save Carpetfizz/155184e661c8f8f083095a9c52f7c2cd to your computer and use it in GitHub Desktop.
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