我有像这样的嵌套资源
resources :profiles do
resources :albums do
resources :images
end
end
match ':username' => "profiles#show", :as => 'profile'
例如,特定图像的网址是
http://localhost:3000/profiles/Azzurrio/albums/4/images/1
我不能在我的模板中使用配置文件用户名,当我使用params [:username]时它不起作用,所以有人能告诉我如何处理这个参数?
答案 0 :(得分:8)
This page(寻找“嵌套路线”)告诉你你想要什么。
简而言之,如果你有上面定义的嵌套资源结构,那么url将包含这个结构:
profiles/:profile_id/albums/:album_id/images/:image_id
所以你正在寻找params[:profile_id]
答案 1 :(得分:3)
如果您运行rake routes
,它还会告诉您各种参数键的名称。