我的路线:

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/

10-11 22:32
查看更多