4

In a production site, I have a homepage defined with route start#index.

This works as expected.

Now, some crawlers are scanning the page for things like /crossdomain.xml and this will trigger the start controller to run and it tries to return a XML view.

Unluckily I did not define a XML view or template or anything about it and as such, error messages are generated (via eMail, so it's quite annoying):

[Exception] start#index (ActionView::MissingTemplate) "Missing template
start/index with {:handlers=>[:rjs, :rhtml, :builder, :rxml, :erb],
:formats=>[:xml], :locale=>[:crossdomain, :en]} in view paths

So I guess there are 2 choices:

  • Disable all things XML/JSON in this app and render the default 404 page.
  • Create a dummy XML view.

I would prefer the first choice, but I'm not sure how this could be done? Thanks for suggestions or a link to a best practice.

EDIT, as requested, the output of rake routes. I see some error in the 2nd last line I guess?

            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"}
Sebastian Roth
  • 11,344
  • 14
  • 61
  • 110

2 Answers2

1

You can use a route constraint so that only html will be accepted as a format. This will give you your first choice.

Take a look at this and this.

Community
  • 1
  • 1
thekindofme
  • 3,846
  • 26
  • 29
1

What does the response block of your controller action contain? If you've left the default block:

respond_to do |format|
  format.html { redirect_to(foobar_url) }
  format.xml  { head :ok }
end

but haven't defined an XML template, you're going to get an error. Remove the format.xml (or if you just want HTML, you can dispense with the respond_to block completely) and any request to a format besides HTML will fail.

Malefactor
  • 122
  • 6