【问题标题】:No "(.:format)" in Rails 3.1 when trying to route site root尝试路由站点根目录时,Rails 3.1 中没有“(.:format)”
【发布时间】:2011-10-07 11:26:15
【问题描述】:

自从升级到 Rails 3.1 后,我的站点路由一直存在问题。以前,使用 Rails 3.0,我可以在我的路由器配置中做到这一点:

resources :quotes, :path => ""
root :to => "quotes#index"

这会给我像 GET /(.:format) 这样的路由,这是我想要的,因为我的 QuotesControllerindex 操作也可以返回 JSON、XML 和 ATOM 格式的数据。

现在,自从升级到 Rails 3.1 后,路由显示如下:GET /(.:format) 消失了,尝试访问 /.atom URL 不再起作用。如何恢复此功能?

编辑:“rake routes CONTROLLER=quotes”输出以下内容:

   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"}

【问题讨论】:

  • rake routes CONTROLLER=quotes 的输出是什么?
  • 我用请求的信息编辑了问题。
  • 你试过 :format => true 吗?只是在这里从臀部射击......
  • 这实际上使它工作得更少——然后除了根路由之外的每条路由都需要一个格式,而根路由根本不起作用——它们只会给我 406 错误。

标签: ruby-on-rails routes ruby-on-rails-3.1


【解决方案1】:

好的,所以,我认为这可能是 Rails 团队故意阻止像“/.atom”这样的 URL 的事情(因为真的,这看起来应该发生吗?),所以我现在使用第二条路由(get "latest", :action => :index)作为 URL 格式(例如,"/latest.atom")。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2011-12-19
    • 2011-11-30
    相关资源
    最近更新 更多