Handling ActionView::MissingTemplate exceptions

Perhaps you’ve been receiving annoying emails about exceptions like this in your Rails apps:

A ActionView::MissingTemplate occurred in posts#destroy:

Missing template posts/destroy with {:formats=>[:html], :locale=>[:en, :en]} in view paths...

This exception is raised when you’re missing the template for responding to a request of a certain format. So, if the browser requested HTML and you only expected to receive JS, you might simply modify your controller action like so:

respond_to do |format|
  format.js
end

This specifies that you’re only going to respond to JS requests, and any others will be served a 406 “not_acceptable” response, which will quiet down that exception noise.

Have you handled these in some other way? If so, please let me know!

Published by

Trevor Turk

A chess-playing machine of the late 18th century, promoted as an automaton but later proved a hoax.