It is almost, but not quite, completely unlike tea.

Sunday, October 01, 2006

A small change to Rails routing

A recent change in the way Rails deals with incoming requests caught me a bit off guard. I was used to being all loosey-goosey with my routes, like saying

/categories/show/34-Detachable-Widgets.html

and having Rails happyily translate that into a request for /categories/show/34. However, when I caught up to edge a few days ago, my tests started failing. Wah? Further investigation revealed that the culprit was that flagrant .html hanging there on the end (why? because I can). After a bit of digging on the Rails mailing list, I finally found my buried treasure: a post by Jeremy Kemper mentioning that Rails now considers . a "URL separator." Ergo, your route

:controller/:action/:id

becomes

:controller/:action/:id.:format

and all's right with the world again. This allows us to force a format just by using it as the extension (i.e. trigger a specific response via responds_to), so I don't mind the change. I just wish someone had mentioned it a bit more loudly... like I'm doing now.

Tags: ,

No comments: