gpt4 book ai didi

ruby-on-rails-3 - ROR 路由描述中的 DRY

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

我在 json rest 应用程序中嵌套了路由组合,用于不同的下拉列表和分组

 resources :cities, :only =>[:index,:show] 
resources :regions, :only =>[:index,:show] do
resources :cities, :only=>[:index, :show]
end
resources :countries, :only=>[:index,:show] do
resources :cities, :only=>[:index,:show]
resources :regions, :only=>[:index,:show]
end

有没有一种方法可以更干脆地描述它?

最佳答案

如果您确实需要这些路线,我认为您无能为力。也许您可以使用 with_options 以更简洁的方式编写它:

  with_options :only => [:index, :show] do |w|

w.resources :cities
w.resources :regions do
w.resources :cities
end

w.resources :countries do
w.resources :cities
w.resources :regions
end

end

关于ruby-on-rails-3 - ROR 路由描述中的 DRY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9113921/

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