My Rails 3 site is getting hit by crawlers with strange accept headers, trigger exceptions as like
ActionView::MissingTemplate occurred in home#show
Here are some of the accept headers causing issues
text/*
application/jxw
*/*;q=0.1
In these cases, this is being interpreted as the format for the request, and as such, causing the missing template error. I don't really care what I return to these crawlers, but just want to avoid the exceptions.
You could rescue from exception like this in your application controller and render the HTML template instead:
class ApplicationController
rescue_from ActionView::MissingTemplate, :with => :render_html
def render_html
if not request.format == "html" and Rails.env.production?
render :format => "html"
else
raise ActionView::MissingTemplate
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With