Rails、path_names 和嵌套资源

发布于 2024-12-25 06:26:39 字数 746 浏览 0 评论 0原文

我的路线:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知足的幸福 2025-01-01 06:26:39

我选择了最后一个选项:

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

I went for the last option:

resources :events, :path_names => { :new => "organize" }
resources :events, :only => [] do
    #nested resources...
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文