ruby-on-rails – 禁用所有XML视图

在生产站点中,我有一个使用route start #index定义的主页.

这按预期工作.

现在,一些爬虫正在扫描页面以查找/crossdomain.xml之类的内容,这将触发启动控制器运行并尝试返回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视图.

我更喜欢第一选择,但我不确定如何做到这一点?感谢您的建议或最佳实践的链接.

根据要求编辑耙路线的输出.我猜到最后一行有些错误?

            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作为格式.这将为您提供首选.

看看thisthis.

点赞