3

我有嵌套用于不同的下拉列表中JSON REST应用路线的组合和分组DRY在ROR路线描述

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 

有没有办法来形容它更干路?

回答

3

如果你真的需要这些路线,我认为你不能做太多的事情。大概你可以用更简洁的方式使用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 
+0

现在看起来更好一点...谢谢 – Fivell 2012-02-02 14:47:29