3

さまざまなドロップダウンリストとグループ化に使用される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

もっとドライな方法で説明する方法はありますか?

4

1 に答える 1

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
于 2012-02-02T14:40:11.790 に答える