Pau*_*hon 8 ruby-on-rails ruby-on-rails-3
我的Rails 3网站受到具有奇怪接受标头的抓取工具的攻击,触发异常等
ActionView::MissingTemplate occurred in home#show
Run Code Online (Sandbox Code Playgroud)
以下是一些导致问题的接受标头
text/*
application/jxw
*/*;q=0.1
Run Code Online (Sandbox Code Playgroud)
在这些情况下,这被解释为请求的格式,因此导致丢失模板错误.我真的不在乎我回到这些抓取工具,但只是想避免异常.
你可以在你的应用程序控制器中从这样的异常中解救并改为呈现HTML模板:
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
Run Code Online (Sandbox Code Playgroud)