This project is archived and is in readonly mode.

#2772 ✓duplicate
J T Calhoun

Routing: 2.3 provides no way to require a :format

Reported by J T Calhoun | June 6th, 2009 @ 11:08 PM | in 2.3.4

Commit #fef6c32 (Added optimal formatted routes to rails, deprecating the formatted_ methods, and reducing routes creation by 50%) solves the problem of redundancy when creating routes which can optionally have a format/file-extension, but removes the ability to require that a format be explicitly provided.

# config/routes.rb

map.connect "sitemap.:format", :controller => "pages", :action => "sitemap"

# app/controllers/pages_controller.rb

def sitemap
    respond_to do |format|

In 2.2.2, the above route coupled with the respond_to block produced the following responses:

/sitemap      404 Not Found
/sitemap.html 406 Not Acceptable
/sitemap.txt  200 OK
/sitemap.xml  200 OK

In 2.3.2, however, the route where no specific format is requested (*/*) remains accessible, displaying the xml document:

/sitemap      200 OK
/sitemap.html 406 Not Acceptable
/sitemap.txt  200 OK
/sitemap.xml  200 OK

This, while not unexpected, remains unintended; and there appears to be no way to make the "all" path unaccessible. --That is, without creating new redundancies (e.g. map.connect("sitemap.xml"), map.connect("sitemap.txt"), ..., etc.)

Further, using :requirements => { :format => /txt|xml/ } in the route doesn't work. --Though it seems using :requirements shouldn't be necessary anyway since routing should probably respect the respond_to block and return 406 Not Acceptable for /sitemap (because format.all is not provided).

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>