Skip to content

Instantly share code, notes, and snippets.

@billhorsman
Created June 13, 2017 10:43
Show Gist options
  • Save billhorsman/1f116e8c926f109c51bd24fb17e60887 to your computer and use it in GitHub Desktop.
Save billhorsman/1f116e8c926f109c51bd24fb17e60887 to your computer and use it in GitHub Desktop.
Handling ActionController::UnknownFormat
class ApplicationController < ActionController::Base
# Rather than return a 500 (internal server error) let's just say we can't
# find what they are looking for. Typically, this is when someone hits one
# of our valid routes but asks for the .xml format or something.
rescue_from ActionController::UnknownFormat, with: :raise_unknown_format
def raise_unknown_format
render plain: 'Unknown Format', status: :not_found
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment