2011-07-11 91 views
1

我使用嵌套資源軌道:在航線資源嵌套

#route.rb 
resources :users do 
    resources :posts 
end 

#route.rb 
match '/:username' => 'users#show', :as => :user 

我改變/user/id/username

但是,如何改變/users/username/postsusername/posts

+0

這本作品是這樣一個共同的要求,我認爲它是關於時間的Rails使之成爲可能。沒有理由必須在任何地方強制使用':id' ......這可以在不使99%的情況下的代碼複雜化的情況下進行配置。不幸的是,我懷疑你會得到你正在尋找的答案;) – d11wtq

回答

1

:id實際上只是它們將用於查找對象的鍵的引用。它不一定需要是整數表示。

看看friendly_id寶石,看看如何完成slu handling處理,以及如何告訴ActiveRecord使用它,而不是它默認預期的整數。

0

#route.rb 
match '/:username/posts' => 'posts#index', :as => :user_posts