gpt4 book ai didi

ruby-on-rails - Rails、path_names 和嵌套资源

转载 作者:行者123 更新时间:2023-12-04 03:40:44 24 4
gpt4 key购买 nike

我的路线:

resources :events, :path_names => { :new => "organize" } do
resources :forums
end

使用这些路由,我会得到类似 /events/:event_id/forums/organize 的 URL。 .我不希望 path_names 传播到我的嵌套路由...我是否必须重新定义 path_names为他们?或使用 scope ?
resources :events, :path_names => { :new => "organize" } do
scope :path_names => { :new => "new" } do
resources :forums
# other nested resources...
end
end

或者(我最喜欢的,直到你找到更好的解决方案;))
resources :events, :path_names => { :new => "organize" }
resources :events, :only => [] do
#nested resources...
end

有没有更优雅的方法来做到这一点?如果你不这么认为,你也可以告诉我你认为哪个最好。

最佳答案

我选择了最后一个选项:

resources :events, :path_names => { :new => "organize" }
resources :events, :only => [] do
#nested resources...
end

关于ruby-on-rails - Rails、path_names 和嵌套资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8721607/

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