Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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