简体   繁体   中英

rails routing nested resources

I have next resources

 resources :countries do
    resources :cities
 end    

 resources :cities do
    resources :streets
 end

it generates next 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 dont want access to cities can be without country id but also I don't want to use 3-levels nested resources, so I can change routes like next

 resources :countries do
        resources :cities
     end    

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

Is there some kind of shortcut to disable all action instead of write all default actions at :except option ????

resources :cities, :only => [] do
    ...
end

You can follow this routes

resources :topics do
    resources :solutions
  end

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM