[英]Rails route to many controllers
我的控制器是:
A::B::C::SomeController
A::B::C::SomeOtherController
A::B::C::ThatController
他們所有人都有行動:show。 我的目標是制作一條漂亮的單線路線,例如:
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
可以在滑軌(4.2)中使用嗎?
更新。 現在我已經停止了循環路由渲染,但是我仍然不滿意。
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
那這樣的事情呢:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.