Search code examples
ruby-on-railsruby-on-rails-4

Rescue ActionController::UnknownFormat from raising an exception


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)

Solution

  • It looks like this was deprecated in Rails 4 in favor of this rescue_from syntax. So something like this:

    application_controller.rb:

      rescue_from ActionController::UnknownFormat, with: :raise_not_found
    
      def raise_not_found
        render(text: 'Not Found', status: 404)
      end