2
我有以下的路線,這使得對於網址像/:username/:project_name
Rails的嵌套的資源和:路徑=>「/」
resources :users, :path => "/" do
resources :projects, :path => "/"
end
的問題是,/:username/edit
不起作用,因爲它正在尋找項目與'編輯'的名稱。
任何方法?謝謝!
我有以下的路線,這使得對於網址像/:username/:project_name
Rails的嵌套的資源和:路徑=>「/」
resources :users, :path => "/" do
resources :projects, :path => "/"
end
的問題是,/:username/edit
不起作用,因爲它正在尋找項目與'編輯'的名稱。
任何方法?謝謝!
這樣做的幾種方法...
1)會給你喜歡/:user_id/:id
路線(你想要的)
match '/:user_id/edit', :to => 'users#edit', :as => :edit_user
resources :users, :except => [:edit], :path => "/" do
resources :projects, :path => "/"
end
2)會給你喜歡/:user_id/projects/:id
路線(這好像你避免)
resources :users, :path => "/" do
resources :projects
end
我個人更喜歡#2,因爲它是清潔的,並提供了一目瞭然的路線更多的知識。
你試圖完成什麼網址結構? – sunkencity 2012-01-12 18:35:29
正如我上面寫的,我想要像'/用戶名/ project_name'和'/用戶名/ project_name_2'的網址。問題是這不允許'/用戶名/編輯'。 – 2012-01-12 18:36:49
您是否嘗試「手動」添加此路線?我會在資源路徑前添加一個匹配「/ username/edit」=>「users#edit」。順便說一下,這個路由設置不是一個好主意。這將導致更多的問題... – phoet 2012-01-12 21:34:16