When you visit
/page?format=foo (and sometimes
/page.foo, depending on the routes) in a Ruby on Rails app, Rails will try to render the action in that format - that is, using the
If you use the
1 2 3 4
syntax, requesting an invalid format gives you an empty “406 Not Acceptable” response.
Actions that do not use this syntax, though, will cause an
ActionController::MissingTemplate exception – which the user sees as an unsightly “500 Internal Server Error”.
That means actions that render implicitly like
1 2 3
as well as explicitly like
1 2 3 4
I don’t want to show the 500 page unless necessary. In this case, a 404 page makes some sense; you could also argue for using a 406 error (for consistency with
respond_to, if nothing else).
I added this to my
1 2 3 4 5 6 7 8
log_exception(e) line should obviously be changed or removed if you don’t use Exception Logger, or don’t want the errors logged.
render_404 was described in an earlier blog post. If you prefer an empty error 406, a simple
should do it.
Note that none of this affects the 406 error when passing an invalid format to a