KJF
KJF

Reputation: 2093

Dry up rails namespaces in routes

I have a couple of namespaces which look identical, the only difference between the two are the names. So I have

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

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

What I would like to do is have the same resources defined in each namespace without needing to make changes in two places when resources are added/removed/changed.

Is there any way to do this?

Upvotes: 4

Views: 191

Answers (1)

kclair
kclair

Reputation: 2224

Isn't this just a ruby file? couldn't you do:

[:narrow, :wide].each do |ns|
  namespace ns do
    resources :posts
    resources :comments
  end
end

Upvotes: 5

Related Questions