Rails、path_names 和嵌套资源
我的路线:
resources :events, :path_names => { :new => "organize" } do
resources :forums
end
通过这些路线,我将获得类似 /events/:event_id/forums/organize
的网址。我不希望 path_names 传播到我的嵌套路由...我是否必须为它们重新定义 path_names
?或者使用范围
?
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
有没有更优雅的方法来做到这一点?如果你不这么认为,你也可以告诉我你认为哪一个最好。
My routes:
resources :events, :path_names => { :new => "organize" } do
resources :forums
end
With these routes, I'll get urls like /events/:event_id/forums/organize
. I don't want the path_names to propagate to my nested routes... Do I have to redefine path_names
for them? Or use scope
?
resources :events, :path_names => { :new => "organize" } do
scope :path_names => { :new => "new" } do
resources :forums
# other nested resources...
end
end
Or (my favorite, until you find a better solution ;))
resources :events, :path_names => { :new => "organize" }
resources :events, :only => [] do
#nested resources...
end
Is there a more elegant way to do this? if you don't think so, you can also tell me which one is the best in your opinion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我选择了最后一个选项:
I went for the last option: