【发布时间】:2017-01-17 16:18:37
【问题描述】:
在我的应用程序控制器中,我正在从一堆不同的异常中解救出来,以毫无问题地显示我自己的错误页面。例如:
rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from ActionView::MissingTemplate, with: :server_error
# etc...
但是以下方法不起作用:
rescue_from AbstractController::ActionNotFound, with: :not_found
我的理解是,在我们到达我的应用程序控制器以便能够拯救它之前,AbstractController 中引发了异常。
我也希望能够从这个异常中解救出来,但我无法找到可行的解决方案。
我尝试通过以下方式向路由器发送异常:
config/application.rb
config.exceptions_app = self.routes
在 config/routes.rb 中
get "*any", via: :all, to: "application#not_found"
这不起作用,似乎是 Rails 3 和 4 最常见的答案。我正在使用 Rails 5.0.0,感谢任何帮助
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-5