【发布时间】:2011-09-28 13:21:47
【问题描述】:
我想在子目录中组织我的控制器。这是一个例子:
routes.rb:
resources :locations do
resources :users
end
我想将我的控制器放在适当的子目录中:
app/controllers/locations/users_controller.rb
并且网址将是(标准):
/locations/1/users
/locations/1/users/new
/locations/1/users/10/edit
...
如果我的路由中有命名空间,我可以将 users_controller.rb 更改为
class Locations::UsersController < LocationsController
end
但它不适用于嵌套资源,而是出现以下错误:
Routing Error
uninitialized constant UsersController
更新
如果我添加它会起作用:
resources :locations do
resources :users
end
match 'locations/:location_id/users' => "locations/users#index"
但我必须为每个操作和嵌套资源添加一个路由...
【问题讨论】:
-
我不确定你想做什么。 isnt ": resources :locations do resources :users end" 让它工作吗?
-
不,在子目录中没有找到users_controller.rb...
标签: ruby-on-rails-3 rails-routing