在一个生产站点中,我有一个用路由start#index
定义的主页。
运行正常
现在,一些爬虫正在扫描页面的东西,如/crossdomain.xml
,这将触发start
控制器运行,它试图返回一个XML视图。
不幸的是,我没有定义XML视图或模板或任何关于它的东西,因此,错误消息生成(通过电子邮件,所以它很烦人):
[Exception] start#index (ActionView::MissingTemplate) "Missing template
start/index with {:handlers=>[:rjs, :rhtml, :builder, :rxml, :erb],
:formats=>[:xml], :locale=>[:crossdomain, :en]} in view paths
所以我想有两个选择:
- 在这个应用程序中禁用所有XML/JSON,并呈现默认的404页面。创建一个虚拟XML视图。
我更喜欢第一个选择,但我不知道这怎么做?感谢您的建议或最佳实践的链接。
EDIT,按要求,rake routes
的输出。我猜最后第二行有错误?
new_editor_session GET /editors/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
editor_session POST /editors/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_editor_session GET /editors/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
/auth/:provider/callback(.:format) {:action=>"create", :controller=>"sessions"}
signout /signout(.:format) {:action=>"destroy", :controller=>"sessions"}
photo_of_week_submissions GET (/:locale)/submissions/photo_of_week(.:format) {:action=>"photo_of_week", :controller=>"submissions"}
select_photo_of_week_submission GET (/:locale)/submissions/:id/select_photo_of_week(.:format) {:action=>"select_photo_of_week", :controller=>"submissions"}
accept_submission GET (/:locale)/submissions/:id/accept(.:format) {:action=>"accept", :controller=>"submissions"}
submissions GET (/:locale)/submissions(.:format) {:action=>"index", :controller=>"submissions"}
POST (/:locale)/submissions(.:format) {:action=>"create", :controller=>"submissions"}
new_submission GET (/:locale)/submissions/new(.:format) {:action=>"new", :controller=>"submissions"}
edit_submission GET (/:locale)/submissions/:id/edit(.:format) {:action=>"edit", :controller=>"submissions"}
submission GET (/:locale)/submissions/:id(.:format) {:action=>"show", :controller=>"submissions"}
PUT (/:locale)/submissions/:id(.:format) {:action=>"update", :controller=>"submissions"}
DELETE (/:locale)/submissions/:id(.:format) {:action=>"destroy", :controller=>"submissions"}
login (/:locale)/login(.:format) {:to=>#<Proc:0x0000000103871938@/Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/routing/mapper.rb:366>}
design (/:locale)/design(.:format) {:action=>"design", :controller=>"page"}
gallery (/:locale)/gallery(.:format) {:action=>"gallery", :controller=>"page"}
features (/:locale)/features(.:format) {:action=>"features", :controller=>"page"}
competition (/:locale)/competition(.:format) {:action=>"index", :controller=>"competition"}
facebook_albums (/:locale)/facebook-albums(.:format) {:action=>"facebook_albums", :controller=>"competition"}
facebook_photos (/:locale)/facebook-photos(.:format) {:action=>"facebook_photos", :controller=>"competition"}
facebook_upload (/:locale)/facebook-upload(.:format) {:action=>"facebook_upload", :controller=>"competition"}
root (/:locale)(.:format) {:action=>"index", :controller=>"start"}
root /(.:format) {:action=>"index", :controller=>"start"}
你可以使用路由约束,这样只接受html作为格式。这将是你的第一选择。
看一下这个和这个
你的控制器动作的响应块包含什么?如果你留下了默认块:
respond_to do |format|
format.html { redirect_to(foobar_url) }
format.xml { head :ok }
end
但是没有定义XML模板,您将得到一个错误。删除format.xml(或者如果只想要HTML,可以完全省略respond_to块),任何对HTML以外格式的请求都将失败。