某些漫游器或其他外部请求ActionController::UnknownFormat
在重定向时导致错误
是否可以在application_controller的某处添加一个万能的方法来处理这些错误?
在请求中添加默认方法的配置规范(如果未指定)?
下面是trace的示例:
An ActionController::UnknownFormat occurred in main#index:
ActionController::UnknownFormat
app/controllers/main_controller.rb:17:in `index'
-------------------------------
Request:
-------------------------------
* URL : http://ownedurl.com/
* HTTP Method: GET
* IP address : 82.xxx.xxx.xxx
* Parameters : {"controller"=>"main", "action"=>"index"}
* Timestamp : 2015-06-07 20:54:32 +0200
* Server : servername
* Rails root : /var/www/ownedurl.com/releases/208
* Process: 29726
获取请求显然可以工作;但它使它发生了。
对此的经验非常感激
这将处理不带格式的请求:
rescue_from ActionController::UnknownFormat, with: :raise_not_found
def raise_not_found
render(text: 'Not Found', status: 404)
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句