干掉路由中的rails名称空间

KJF*_*KJF 4 routing namespaces ruby-on-rails ruby-on-rails-3

我有几个看起来相同的命名空间,两者之间的唯一区别是名称.所以我有

namespace :narrow do
  resources :posts
  resources :comments
  ...
  ...
end

namespace :wide do
  resources :posts
  resources :comments
  ...
  ...
end
Run Code Online (Sandbox Code Playgroud)

我想要做的是在每个命名空间中定义相同的资源,而无需在添加/删除/更改资源时在两个位置进行更改.

有没有办法做到这一点?

kcl*_*air 5

这不仅仅是一个ruby文件吗?你不能这样做:

[:narrow, :wide].each do |ns|
  namespace ns do
    resources :posts
    resources :comments
  end
end
Run Code Online (Sandbox Code Playgroud)