Rails路由到许多控制器

时间:2016-03-11 04:42:25

标签: ruby-on-rails routing

我的控制器是:

A::B::C::SomeController  
A::B::C::SomeOtherController  
A::B::C::ThatController

所有人都有行动:表演。我的目标是制作一条漂亮的单线路线,如:

scope :beautiful do
  scope :route_to do
    get ':controller' => 'a/b/c/:controller#show'
  end
end

在地址栏中查看它们,如:

beautiful/route_to/some  
beautiful/route_to/some_other  
beautiful/route_to/that  

可以在rails(4.2)中使用吗?

UPD。现在我已经停止了循环路线渲染,但我仍然不满意。

scope :beautiful do
  scope :route_to do
    A::B::C::BaseController.descendants.each do |my_controller|
      scope controller: my_controller, module: 'a/b/c' do
        get my_controller, action: :show
        post my_controller, action: :update
      end
    end
  end
end

1 个答案:

答案 0 :(得分:0)

这样的事情:

namespace :a do
  namespace :b do
    namespace :c do
      resource :something, only: [:show] # => will take controller A::B::C::SomethingController (file must be located at: app/controllers/a/b/c/something_controller.rb)
      resource :something_other, only: [:show]
      ...
    end
  end
end