ApplicationController中的rescue_from没有捕获异常

时间:2016-01-13 15:58:58

标签: ruby-on-rails ruby activeadmin cancan cancancan

我正在设置一个简单的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,而是显示异常,就像它没有被捕获一样。

enter image description here

有任何线索吗?谢谢!

0 个答案:

没有答案