Define a route that only responds to a specific format

You won't usually have to do this. It's OK to route all formats to a controller, and let the controller decide to which format it wants to respond.

Should you for some reason want to define a route that only responds to a given format, here is how you do it:

Rails 3

match 'sitemap.xml' => 'feeds#sitemap', :constraints => { :format => 'xml' }, :as => 'sitemap'

Rails 2

map.sitemap 'sitemap.xml', :controller => 'feeds', :action => 'sitemap', :format => 'xml'
Henning Koch About 12 years ago