gpt4 book ai didi

ruby-on-rails - rails 路由嵌套资源

转载 作者:行者123 更新时间:2023-12-04 05:42:55 25 4
gpt4 key购买 nike

我有下一个资源

 resources :countries do
resources :cities
end

resources :cities do
resources :streets
end

它生成下一条路线
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

我不想在没有国家/地区 ID 的情况下访问城市,但我也不想使用 3 级嵌套资源,因此我可以更改路线,如下所示
 resources :countries do
resources :cities
end

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

是否有某种快捷方式可以禁用所有操作而不是在 :except 选项中写入所有默认操作????

最佳答案

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

关于ruby-on-rails - rails 路由嵌套资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9031277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com