Created
April 4, 2019 02:15
-
-
Save leemcalilly/68ca89f3c9e193266c9b9d9287263978 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
class ApplicationController < ActionController::Base | |
include Clearance::Controller | |
before_action :require_login | |
before_action :require_account | |
include Pundit | |
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized | |
private | |
def user_not_authorized(exception) | |
policy_name = exception.policy.class.to_s.underscore | |
flash[:error] = t "#{policy_name}.#{exception.query}", scope: "pundit", default: :default | |
redirect_to(request.referrer || root_path) | |
end | |
def require_account | |
if current_user && current_user.account.blank? | |
redirect_to new_account_path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment