3

我有这样的嵌套资源

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

我不能在模板中使用个人资料用户名,当我使用 params[:username] 时它不起作用,所以谁能告诉我如何处理这个参数?

4

2 回答 2

8

这个页面(寻找“嵌套路由”)告诉你你想要什么。

简而言之,如果你有上面定义的嵌套资源结构,那么 url 将包含这个结构:

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

所以你正在寻找params[:profile_id]

于 2012-05-13T05:09:46.267 回答
3

如果您运行rake routes它,它还会告诉您各种参数键的名称。

于 2012-05-13T05:11:02.653 回答