Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leemcalilly/68ca89f3c9e193266c9b9d9287263978 to your computer and use it in GitHub Desktop.
Save leemcalilly/68ca89f3c9e193266c9b9d9287263978 to your computer and use it in GitHub Desktop.
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