There are many possible ways to implement this feature: * Adding a custom middleware * Using rack-attack with a blocklist * Using routes constraints We're choosing to use a controller concern with a redirect because it's what we do to handle unauthorized cancancan exceptions.
15 lines
319 B
Ruby
15 lines
319 B
Ruby
class Admin::BaseController < ApplicationController
|
|
include IpDeniedHandler
|
|
layout "admin"
|
|
before_action :authenticate_user!
|
|
|
|
skip_authorization_check
|
|
before_action :verify_administrator
|
|
|
|
private
|
|
|
|
def verify_administrator
|
|
raise CanCan::AccessDenied unless current_user&.administrator?
|
|
end
|
|
end
|