Skip to content

Instantly share code, notes, and snippets.

@nicedawg
Last active June 28, 2020 00:09
Show Gist options
  • Save nicedawg/5f003af093d7db2c9829b85a8a7a4bc5 to your computer and use it in GitHub Desktop.
Save nicedawg/5f003af093d7db2c9829b85a8a7a4bc5 to your computer and use it in GitHub Desktop.
[Beginning Rails 6] Listing 8-22. Modified app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
helper_method :current_user, :logged_in?
def current_user
return unless session[:user_id]
@current_user ||= User.find_by(id: session[:user_id])
end
def authenticate
logged_in? || access_denied
end
def logged_in?
current_user.present?
end
def access_denied
redirect_to(login_path, notice: "Please log in to continue") and return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment