我正在设置一个简单的RoR应用程序。它将ActiveAdmin与CanCan混合以管理授权。当我提出CanCan::AccessDenied
时,异常永远不会被解除:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
protect_from_forgery
# Ensure authorization happens on every action in your application
check_authorization
# If the user authorization fails, a CanCan::AccessDenied exception will be raised
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :alert => exception.message
end
def access_denied!(exception)
raise CanCan::AccessDenied.new exception.message
end
end
不会重定向到root_url
,而是显示异常,就像它没有被捕获一样。
有任何线索吗?谢谢!