Rail drying in route spaces

I have a couple of namespaces that look the same, the only difference between them is the names. So i

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

What I would like to do is the same resources that are defined in each namespace, without the need to make changes in two places when adding / removing / changing resources.

Is there any way to do this?

+4
source share
1 answer

Isn't that just a ruby ​​file? You could not:

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

Source: https://habr.com/ru/post/1401429/


All Articles