2012-05-13 46 views
3

的名字,我有一個嵌套的資源,這樣什麼params用於在嵌套資源

resources :profiles do 
    resources :albums do 
     resources :images 
    end 
    end 
match ':username' => "profiles#show", :as => 'profile' 

從而例如特定圖像的URL是

http://localhost:3000/profiles/Azzurrio/albums/4/images/1 

我不能使用內部資料會員名稱我模板,當我使用參數[:用戶名]它不起作用,所以任何人都可以告訴我如何處理這個參數?

回答

8

This page(尋找「嵌套路線」)告訴你你想要什麼。

總之,如果你有你上面定義的嵌套的資源結構,那麼該URL將包含此結構:

profiles/:profile_id/albums/:album_id/images/:image_id

所以你要找params[:profile_id]

3

如果您運行rake routes它也會告訴你各種參數鍵的名字。

+0

我不知道。有趣! – Davidann