This project is archived and is in readonly mode.
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|
format.xml
format.text
end
end
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
-
Michael Koziarski June 9th, 2009 @ 09:43 AM
- Milestone changed from 2.x to 2.3.4
-
CancelProfileIsBroken August 7th, 2009 @ 01:58 PM
- Tag changed from format, formats, respond_to, route, router, routes, routing to bugmash, format, formats, respond_to, route, router, routes, routing
-
Adam Bair August 9th, 2009 @ 10:22 PM
Verified. I tried this in 2.2.2 and 2.3.2 and experienced the same behavior as Jason.
-
Adam Bair August 9th, 2009 @ 10:28 PM
I've attached a patch that includes a test case that exposes this bug in 2.3.2.
-
josh August 10th, 2009 @ 02:26 AM
- State changed from new to duplicate
If we can fix :requirements on :format, we can have hacky support for required formats in 2.3. That permanent optionalize was a big changed and caused some annoying side effects. In 3.0, we will have real syntax to optionalize segments.
Please follow up on #2151
-
Jeremy Kemper August 10th, 2009 @ 07:10 AM
- Tag changed from bugmash, format, formats, respond_to, route, router, routes, routing to format, formats, respond_to, route, router, routes, routing
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>