Routing problem when using :format

Using edge rails, latest revision.

routes.rb:   map.connect ':controller/:action/:id.:format'   map.connect ':controller/:action/:id'

When I enter a url such as http://localhost:3000/player/genres everything works fine, but when I enter /player/genres.xml I get a routing error. I have both a genres.rhtml and genres.rxml in my /app/views/player folder. Do I need to something different to my routes.rb configuration?

This is my player_controller.rb   def genres     @genres = Genre.tree

    respond_to do |type|       type.html       type.xml     end   end

From the log:

Processing ApplicationController#index (for 127.0.0.1 at 2006-12-20 16:22:38) [GET]   Session ID: 0b17ff392aa5ccd353c44e641e868772   Parameters: {}

ActionController::RoutingError (no route found to match "/player/genres.xml" with {:method=>:get}):     /vendor/rails/actionpack/lib/action_controller/routing.rb:1263:in `recognize_path'     /vendor/rails/actionpack/lib/action_controller/routing.rb:1253:in `recognize'     /vendor/rails/railties/lib/dispatcher.rb:40:in `dispatch'

This:

  /player/genres.xml

does not match this:

  :controller/:action/:id.:format

If you want that, you have to define a route like:

  :controller/:action.:format

Really? I was reading the weblog on ruby on rails and DHH left this note under the "Formats and responds_to" section (Ruby on Rails — Rails 1.2: Release Candidate 1)

All new applications will have one additional default route: map.connect ':controller/:action/:id.:format'. With this route installed, imagine the following example:

class WeblogController < ActionController::Base   def index     @posts = Post.find :all     respond_to do |format|       format.html       format.xml { render :xml => @posts.to_xml }       format.rss { render :action => "feed.rxml" }     end   end end GET /weblog # returns HTML from browser Accept header GET /weblog.xml # returns the XML GET /weblog.rss # returns the RSS

I thought that :id only matched if it is specified but will default without if necessary. I also have an index action doing /player and /player.xml, but resulting in the same problems (/player.xml gives a routing error). I am using REST for my model classes, but the player isn't a model and doesn't CRUD.

Since I have two actions in the player_controller index and genres, what route would I need to satisfy both /player.xml and /player/genres.xml as well as /player and /player/genres? It seems that by using map.connect ":controller/:action.:format" I can do /player/genres.xml but not /player.xml, though /player/index.xml seems to work.

It would seem like map.connect ':controller/:action/:id.:format' would be correct, but it doesn't seem to work. Shouldn't the defaults => { :action => "index", :id => nil } be used in the absence of :action or :id?