4

In my application_controller.rb I catch all 404s with a render_404 method:

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.

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. I'm guessing this is due to the addition of variants, but I couldn't find exactly what's wrong in the Rails code.

Commenting out the format.html line makes the format.all line work. 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. Any idea how to fix this?

ben
  • 1,432
  • 12
  • 17
  • Maybe a stretch, but is your related view file named with proper extensions? (errors/error_404.html.erb) Usually that throws a view-related error, but can't hurt to check. – Dan L Dec 03 '14 at 14:53
  • Just checked, the extensions are proper indeed. I don't know if that's still a problem though, I'm on Rails 4.1.6 and I haven't seen that issue pop up in a while. – ben Dec 03 '14 at 20:02

1 Answers1

0

format is an object of ActionController::MimeResponds::Collector class. Maybe you can check the API for more info.

udit mittal
  • 529
  • 3
  • 14