我继承了一个项目,以前的开发人员将其添加到了应用程序 Controller 中:

rescue_from Exception, :with => :render_500

我认为这是要抓住这一点并呈现一个动态页面。静态页面是不可接受的,但是现在我不确定为什么。无论如何,这使我无法使用Exceptional捕获异常。呈现动态错误页面后,是否有任何方法可以重新引发异常?

我尝试了这个:
def rescue_from(exception)
  respond_to |format|
    format.html { #render the page# }
  end
  raise exception
end

但是,这显然是行不通的。有任何想法吗?

最佳答案

您可以手动发布到例外-而不是尝试重新发布并让Exceptions捕捉和发布。

def rescue_from(exception)
  ::Exceptional::Catcher.handle(exception)
  respond_to |format|
    format.html { #render the page# }
  end
end

关于ruby-on-rails - Rails rescue_from重新引发异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13826081/

10-12 12:23
查看更多