No "(.:format)" in Rails 3.1 when trying to route site root
Since upgrading to Rails 3.1, I've been having a problem with my site's routing. Previously, with Rails 3.0, I was able to do this in my router config:
resources :quotes, :path => ""
root :to => "quotes#index"
That would give me routes like GET /(.:f开发者_Python百科ormat)
and such, which is what I want since the index
action of my QuotesController
can also return data in JSON, XML and ATOM.
Now, since upgrading to Rails 3.1, the routes have been showing up like this: GET /
. The (.:format)
is gone, and trying to access the /.atom
URL doesn't work anymore. How can I get this functionality back?
EDIT: "rake routes CONTROLLER=quotes" outputs the following:
about_quotes GET /about(.:format) {:action=>"about", :controller=>"quotes"}
top_quotes GET /top(.:format) {:action=>"top", :controller=>"quotes"}
random_quotes GET /random(.:format) {:action=>"random", :controller=>"quotes"}
search_quotes GET /search(.:format) {:action=>"searchform", :controller=>"quotes"}
POST /search(.:format) {:action=>"search", :controller=>"quotes"}
nonsense_quotes GET /nonsense(.:format) {:action=>"nonsense", :controller=>"quotes"}
tags_quotes GET /tags(.:format) {:action=>"tags", :controller=>"quotes"}
tag_quotes GET /tags/:id(.:format) {:action=>"tag", :controller=>"quotes"}
stats_quotes GET /stats(.:format) {:action=>"stats", :controller=>"quotes"}
up_quote GET /:id/up(.:format) {:action=>"up", :controller=>"quotes"}
down_quote GET /:id/down(.:format) {:action=>"down", :controller=>"quotes"}
quotes GET / {:action=>"index", :controller=>"quotes"}
POST / {:action=>"create", :controller=>"quotes"}
new_quote GET /new(.:format) {:action=>"new", :controller=>"quotes"}
edit_quote GET /:id/edit(.:format) {:action=>"edit", :controller=>"quotes"}
quote GET /:id(.:format) {:action=>"show", :controller=>"quotes"}
PUT /:id(.:format) {:action=>"update", :controller=>"quotes"}
DELETE /:id(.:format) {:action=>"destroy", :controller=>"quotes"}
root / {:controller=>"quotes", :action=>"index"}
Okay, so, I've decided that this was probably something that the Rails team did intentionally to discourage URLs like "/.atom" (because really, does that look like something that should happen?), so I'm now using a second route (get "latest", :action => :index) for the format URLs (so, like, "/latest.atom") instead.
精彩评论