首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套路由

嵌套路由
EN

Stack Overflow用户
提问于 2009-07-03 21:13:21
回答 3查看 167关注 0票数 1

如何编写映射这样的路径的路由?

/powerusers/bob/文章标题

这就是我到目前为止得到的:

代码语言:javascript
复制
map.resources :users, :as => "powerusers" do |users|
  users.resources :articles, :as => ''
end

这为我提供了以下路径:

/powerusers/:user_id//:id

如何摆脱双重backslah? /powerusers/admin//first-article?

诚挚的问候。Asbjørn Morell

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-07-03 21:19:10

好吧,如果你不想要中间嵌套资源(/articles),我根本就不会使用map.resources。

尝试:

代码语言:javascript
复制
map.connect '/powerusers/:user_id/:article_title', :controller => 'articles', :action => 'view_by_title'
票数 4
EN

Stack Overflow用户

发布于 2009-07-03 21:24:39

如果我加上...

代码语言:javascript
复制
  map.resources :users, :as => "powerusers" do |users|
    users.resources :entries, :as => 'article-title'
  end

我得到了下面的路线,其中包括你想要的路线...

(根据您的情况,将“文章”替换为“条目”。)

代码语言:javascript
复制
                GET    /powerusers(.:format)                                 {:controller=>"users", :action=>"index"}
                POST   /powerusers(.:format)                                 {:controller=>"users", :action=>"create"}
                GET    /powerusers/new(.:format)                             {:controller=>"users", :action=>"new"}
                GET    /powerusers/:id/edit(.:format)                        {:controller=>"users", :action=>"edit"}
                GET    /powerusers/:id(.:format)                             {:controller=>"users", :action=>"show"}
                PUT    /powerusers/:id(.:format)                             {:controller=>"users", :action=>"update"}
                DELETE /powerusers/:id(.:format)                             {:controller=>"users", :action=>"destroy"}
   user_entries GET    /powerusers/:user_id/article-title(.:format)          {:controller=>"entries", :action=>"index"}
                POST   /powerusers/:user_id/article-title(.:format)          {:controller=>"entries", :action=>"create"}
 new_user_entry GET    /powerusers/:user_id/article-title/new(.:format)      {:controller=>"entries", :action=>"new"}
edit_user_entry GET    /powerusers/:user_id/article-title/:id/edit(.:format) {:controller=>"entries", :action=>"edit"}
     user_entry GET    /powerusers/:user_id/article-title/:id(.:format)      {:controller=>"entries", :action=>"show"}
                PUT    /powerusers/:user_id/article-title/:id(.:format)      {:controller=>"entries", :action=>"update"}
                DELETE /powerusers/:user_id/article-title/:id(.:format)      {:controller=>"entries", :action=>"destroy"}
票数 1
EN

Stack Overflow用户

发布于 2009-07-03 21:47:30

这不是嵌套,这能行得通吗?

代码语言:javascript
复制
map.resources :users, :as => "powerusers"
map.resources :articles, :path_prefix => '/powerusers/:user_id'

我认为它不会,但快速测试会更好:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1080850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档