Rails nested resource routing

I have the following resources

resources :countries do resources :cities end resources :cities do resources :streets end 

it generates the following routes

 GET /countries/:country_id/cities(.:format) cities#index POST /countries/:country_id/cities(.:format) cities#create new_country_city GET /countries/:country_id/cities/new(.:format) cities#new edit_country_city GET /countries/:country_id/cities/:id/edit(.:format) cities#edit GET /countries/:country_id/cities/:id(.:format) cities#show PUT /countries/:country_id/cities/:id(.:format) cities#update DELETE /countries/:country_id/cities/:id(.:format) cities#destroy ...... cities GET /cities(.:format) cities#index POST /cities(.:format) cities#create new_city GET /cities/new(.:format) cities#new edit_city GET /cities/:id/edit(.:format) cities#edit city GET /cities/:id(.:format) cities#show PUT /cities/:id(.:format) cities#update DELETE /cities/:id(.:format) cities#destroy 

I don’t want access to cities without a country identifier, but also I don’t want to use 3-level invested resources, so I can change routes, like the following

  resources :countries do resources :cities end resources :cities, :except => [:index, :destroy, :edit, :show, :create, :new, :update] do resources :streets end 

Is there any shortcut to disable all actions instead of recording all actions by default: except for the option ????

+7
source share
2 answers
 resources :cities, :only => [] do ... end 
+15
source

You can follow these routes

  resources: topics do
     resources: solutions
   end

   resources: solutions, only: [] do
     resources: reviews, except: [: show,: index]
   end
+1
source

All Articles