Disabling All XML Views

In the workplace, I have a page defined using the start#index route.

This works as expected.

Now some scanners are viewing the page for things like /crossdomain.xml , and this will start controller and it will try to return the XML view.

Unfortunately, I did not define an XML representation or template or anything like that, and thus error messages are generated (via eMail, so this is pretty 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 think there are 2 options:

  • Disable all XML / JSON in this application and display the 404 page by default.
  • Create a dummy XML view.

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

EDIT , as requested, the output of rake routes . Do I see some error in the second last line that I assume?

  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"} 
+4
source share
2 answers

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

Look this one and this one .

+1
source

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

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

but did not define an XML template, you will get an error. Delete the format.xml file (or if you just want HTML, you can completely abandon the response_to block), and any request in a format other than HTML will fail.

+1
source

All Articles