2012-05-13 47 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