本文介绍了从引发异常中拯救 ActionController::UnknownFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力使 ActionController::UnknownFormat
不会在生产中引发异常报告.我正在使用 Rails 4 并认为这样的事情可以解决问题,但似乎没有什么区别:
I am trying to make it so that an ActionController::UnknownFormat
will not raise an exception report in production. I'm using Rails 4 and thought something like this would do the trick, but it doesn't seem to make a difference:
application.rb
config.action_dispatch.rescue_responses.merge!('ActionController::UnknownFormat' => :not_found)
推荐答案
看起来这在 Rails 4 中已被弃用,以支持这种 rescue_from
语法.所以是这样的:
It looks like this was deprecated in Rails 4 in favor of this rescue_from
syntax. So something like this:
application_controller.rb:
application_controller.rb:
rescue_from ActionController::UnknownFormat, with: :raise_not_found
def raise_not_found
render(text: 'Not Found', status: 404)
end
这篇关于从引发异常中拯救 ActionController::UnknownFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!