嵌套控制器和子文件夹的 Rails 3 路由 [英] Rails 3 routes for nested controllers and sub-folders
问题描述
我需要一些有关嵌套控制器路由的帮助.我自己无法从 Rails 指南文档中弄清楚.
我在 rails 3.2 应用程序中有以下控制器:
I need some help with routes for nested controllers. I can't figure out from the Rails guide docs by myself.
I have the following controllers in a rails 3.2 app:
/app/controllers/organizations_controller.rb (class OrganizationsController)
/app/controllers/organization/events_controller.rb (class Organization::EventsController)
然后,在 routes.rb
then, in routes.rb
resources :organizations, path: 'org' do
resources :events
member do
get 'confirm'
end
end
end
running rake routes
显示(仅与我的问题相关的部分):
running rake routes
shows (only the relevant part for my issue):
organization_event GET /org/:organization_id/events/:id(.:format) events#show
URL没问题,路由名也可以,但是到controller/action"的映射不对.不像我想要的那样.它应该是 organization/events#show
.
The URL is ok, the route name is also ok, but the mapping to the "controller/action" is not right. Not as I want it to be. It should be organization/events#show
.
我错过了什么?如何将此路线指向正确的控制器.我选择将 events_controller
放在 organization
文件夹中,因为我已经将另一个 events_controller
放在了controller 文件夹的根目录中,并且它们有不同的目的.
谢谢
What am I missing? How can I point this route to the correct controller. I chose to put the events_controller
in the organization
folder, because I already have another events_controller
placed in the root of the controllers folder, and they have different purposes.
Thank you
推荐答案
namespace :organization do
resources :events
member do
get "confirm"
end
end
end
更多信息此处.
编辑
抱歉,没有正确理解您.
Sorry, didn't understand you correctly.
resources :organizations, path: 'org' do
resources :events, :module => "organization"
member do
get 'confirm'
end
end
end
这是否符合您的需求?
这篇关于嵌套控制器和子文件夹的 Rails 3 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!