嵌套资源的参数名称是什么?

Azz*_*rio 3 ruby ruby-on-rails nested-forms restful-url

我有这样的嵌套资源

resources :profiles do
    resources :albums do
      resources :images 
    end
  end
match ':username' => "profiles#show", :as => 'profile'
Run Code Online (Sandbox Code Playgroud)

例如,特定图像的网址是

http://localhost:3000/profiles/Azzurrio/albums/4/images/1
Run Code Online (Sandbox Code Playgroud)

我不能在我的模板中使用配置文件用户名,当我使用params [:username]时它不起作用,所以任何人都可以告诉我如何处理这个参数?

Dav*_*ser 8

这个页面(寻找"嵌套路线")告诉你你想要什么.

简而言之,如果您具有上面定义的嵌套资源结构,那么url将包含以下结构:

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

所以你在寻找 params[:profile_id]