0

我想在 case routes.rb 下面做一个简单的表达

 namespace :post do
    namespace :p01 do
      resources :p9_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p8_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p7_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p6_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p5_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p4_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p3_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p2_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p1_posts
    end
  end
  namespace :post do
    namespace :p01 do
      resources :p0_posts
    end
  end

我想制作简单的表达式来使用循环我该怎么做

也在下面

  namespace :post do
    namespace :p10 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p09 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p08 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p07 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p06 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p05 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p04 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p03 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p02 do
      resources :posts do
        resources :comments
      end
    end
  end
  namespace :post do
    namespace :p01 do
      resources :posts do
        resources :comments
      end
    end
  end
4

1 回答 1

0

您可以尝试像这样重写它:

namespace :post do
  namespace :p01 do
    9.downto(0) { |i| resources "p#{i}_posts".to_sym }
  end
end
于 2013-06-06T07:06:54.753 回答