5

我使用Rails 3.2Rails的路由像github上

我想有路由非常酷似github上,所以:

root/(username) 
root/(username)/(projectname) 
root/(username)/(projectname)/issus 

我想是这样的:

resources :publishers do 
    resources :magazines do 
    resources :photos 
    end 
end 

但是,让这样的路线:

/publishers/1/magazines/2/photos/3 

我正在看的一个项目做了以下工作,似乎工作,但似乎并不适合我。

resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do 
member do 
    get "team" 
    get "wall" 
    get "graph" 
    get "files" 
end 

resources :wikis, :only => [:show, :edit, :destroy, :create] do 
    member do 
    get "history"   
    end 
end 

回答

4

如果你想摆脱id号(这是rails默认值),并使用名称,我建议FriendlyId宝石。

关注此railscast http://railscasts.com/episodes/314-pretty-urls-with-friendlyid

,这里是GitHub的页面https://github.com/norman/friendly_id

编辑

这是我一直在寻找的文章中,我忘了我几个月前书签它。 http://jasoncodes.com/posts/rails-3-nested-resource-slugs

+0

看起来很有趣。我得看看那个railscast。我想知道它是如何存储在内部的,如果使用不同的数据库很重要。 – Ron 2012-07-17 18:41:31

+1

这很酷。不完全是我想要的,但会有所帮助。我更加关注的是github的工作原理。所以你不需要像/ users/Jonovono这样的url,而只需要/ Jonovono的作品。 – Jonovono 2012-07-17 19:15:26

+1

http://stackoverflow.com/questions/2968722/github-url-style – 2012-07-17 19:18:20

0

您必须使用friendly_id和范围

scope '/:username/:projectname', module: 'users/projects', as: 'users_project' do 
    resources :issus 
    resources :photos 
end