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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)