否“(。:format)”在Rails 3.1中尝试路由站点根目录时 [英] No "(.:format)" in Rails 3.1 when trying to route site root
问题描述
自从升级到Rails 3.1以来,我的网站路由一直存在问题。以前,在Rails 3.0中,我可以在路由器配置中执行此操作:
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"
这会给我类似 GET /(的路线。 :format)
等,这就是我想要的自 QuotesController
index 动作以来的结果>也可以用JSON,XML和ATOM返回数据。
That would give me routes like GET /(.:format)
and such, which is what I want since the index
action of my QuotesController
can also return data in JSON, XML and ATOM.
现在,自升级到Rails 3.1以来,路由一直像这样显示: GET /
。 (.: format)
不见了,尝试访问 /。atom
URL不再有效。我如何才能恢复该功能?
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?
编辑: rake route CONTROLLER = quotes输出以下内容:
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"}
推荐答案
好的,所以,我认为这可能是Rails团队故意阻止诸如 /.atom之类的URL的原因。 (因为实际上,这看起来像应该发生的事情吗?),所以我现在使用第二种路由(获取最新,:action =>:index)作为格式URL(例如, / latest)。原子)。
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.
这篇关于否“(。:format)”在Rails 3.1中尝试路由站点根目录时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!