gpt4 book ai didi

ruby-on-rails - 嵌套资源的参数名称是什么

转载 作者:数据小太阳 更新时间:2023-10-29 07:43:26 26 4
gpt4 key购买 nike

我有这样的嵌套资源

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] 时它不起作用,所以谁能告诉我如何处理这个参数?

最佳答案

This page (寻找“嵌套路线”)告诉你你想要什么。

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

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

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

关于ruby-on-rails - 嵌套资源的参数名称是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10569437/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com