简体   繁体   English

更新到rails 4.1后的ActionController :: UnknownFormat

[英]ActionController::UnknownFormat after update to rails 4.1

In my application_controller.rb I catch all 404s with a render_404 method: 在我的application_controller.rb我使用render_404方法捕获所有404:

def render_404(exception)
  respond_to do |format|
    format.html { render template: 'errors/error_404', layout: 'layouts/application', status: 404 }
    format.all { render nothing: true, status: 404 }
  end
end

The second line used to work fine for all formats other than HTML, which is particularly useful when bots throw random page requests at you. 第二行用于除HTML之外的所有格式都能正常工作,这在机器人向您发送随机页面请求时特别有用。

After updating from Rails 4.0.4 to 4.1.1, requests for non-HTML formats throw ActionController::UnknownFormat errors at me, which triggers a 500 and sends me an email. 从Rails 4.0.4更新到4.1.1后,对非HTML格式的请求会向我抛出ActionController::UnknownFormat错误,触发500并向我发送电子邮件。 I'm guessing this is due to the addition of variants, but I couldn't find exactly what's wrong in the Rails code. 我猜这是由于添加了变种,但我无法找到Rails代码中的确切错误。

Commenting out the format.html line makes the format.all line work. 注释掉format.html线使得format.all线工作。 I can probably hack my render_500 method to react in a specific way when it gets a ActionController::UnknownFormat but that's not ideal. 当它获得ActionController::UnknownFormat时,我可能会破解我的render_500方法以特定的方式做出反应,但这并不理想。 Any idea how to fix this? 知道如何解决这个问题吗?

format is an object of ActionController::MimeResponds::Collector class. format是ActionController :: MimeResponds :: Collector类的对象。 Maybe you can check the API for more info. 也许您可以查看API以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM