Read more

Define a route that only responds to a specific format

Henning Koch
April 03, 2012Software engineer at makandra GmbH

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.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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'
Posted by Henning Koch to makandra dev (2012-04-03 17:28)