Rad*_*gut 5 ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2
我需要一些嵌套控制器路由的帮助.我自己无法从Rails指南文档中找到答案.
我在rails 3.2 app中有以下控制器:
/app/controllers/organizations_controller.rb (class OrganizationsController)
/app/controllers/organization/events_controller.rb (class Organization::EventsController)
Run Code Online (Sandbox Code Playgroud)
然后,在routes.rb中
resources :organizations, path: 'org' do
resources :events
member do
get 'confirm'
end
end
end
Run Code Online (Sandbox Code Playgroud)
正在运行的rake routes节目(只有我的问题的相关部分):
organization_event GET /org/:organization_id/events/:id(.:format) events#show
Run Code Online (Sandbox Code Playgroud)
URL没问题,路由名称也没问题,但是到"控制器/操作"的映射是不对的.不像我想要的那样.它应该是organization/events#show.
我错过了什么?如何将此路径指向正确的控制器.我选择把它events_controller放在organization文件夹中,因为我已经将另一个events_controller放在controllers文件夹的根目录中了,它们有不同的用途.
谢谢
namespace :organization do
resources :events
member do
get "confirm"
end
end
end
Run Code Online (Sandbox Code Playgroud)
更多信息在这里.
编辑
对不起,没听错你的意思.
resources :organizations, path: 'org' do
resources :events, :module => "organization"
member do
get 'confirm'
end
end
end
Run Code Online (Sandbox Code Playgroud)
这符合您的需求吗?
| 归档时间: |
|
| 查看次数: |
6095 次 |
| 最近记录: |