MissingTemplate error in Rails due to incorrect formats sent by browsers
I'm running into an issue where occasionally, a browser fails to send the right list of formats when making a request, and as a result a MissingTemplate error is thrown. I have actions that only respond to JS: e.g., something like:
blah_controller.rb:
def BlahController < ActionController::Base
respond_to :js, :only => :my_action
def my_action
# stuff
end
end
my_action.js.erb:
doSomething();
The vast majority of the time, jQuery makes an a开发者_如何学JAVAjax request, and the resulting JavaScript is executed -- doSomething() is called. But occasionally, the browser sends a format list that does not include JS, and so an ActionView::MissingTemplate
error is thrown:
ActionView::MissingTemplate: Missing template blah/my_action with {:formats=>[:html], :handlers=>[:rjs, :rhtml, :erb, :rxml, :builder], :locale=>[:en, :en]} in view paths ...
This happens on different browsers, so I can't attribute it to some obscure browser, but I haven't been able to reproduce it.
Given you can't reproduce the issue and it only seems to happen in your production env, it's possible some bots are requesting your page incorrectly. The difference you are seeing in browsers could be from spoofed user-agents.
I'd check the IPs of the failed requests against something like Project Honeypot
http://www.projecthoneypot.org/
精彩评论