Reputation: 113
How to set up 2 level deep nested resources controller in Rails 4?
I added the controller paths. I am not sure if that is what was asked.
Ive tried it using class Presupuestos::Ordenes::OrdeneItemsController
but it returns an error:
ActionController::RoutingError at /presupuestos/2/ordenes/1/orden_items/new
uninitialized constant Ordenes.
ActionDispatch::Routing::RouteSet::Dispatcher#controller
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb, line 62
ActionDispatch::Routing::RouteSet::Dispatcher#controller
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb, line 57
ActionDispatch::Routing::RouteSet::Dispatcher#serve
Controller Paths
presupuesto_ordene_orden_items GET /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items(.:format) presupuestos/ordenes/orden_items#index
POST /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items(.:format) presupuestos/ordenes/orden_items#create
new_presupuesto_ordene_orden_item GET /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items/new(.:format) presupuestos/ordenes/orden_items#new
edit_presupuesto_ordene_orden_item GET /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items/:id/edit(.:format) presupuestos/ordenes/orden_items#edit
presupuesto_ordene_orden_item GET /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items/:id(.:format) presupuestos/ordenes/orden_items#show
PATCH /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items/:id(.:format) presupuestos/ordenes/orden_items#update
PUT /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items/:id(.:format) presupuestos/ordenes/orden_items#update
DELETE /presupuestos/:presupuesto_id/ordenes/:ordene_id/orden_items/:id(.:format) presupuestos/ordenes/orden_items#destroy
Routes.rb
resources :presupuestos do
collection { post :import }
resources :ordenes, controller: 'presupuestos/ordenes' do
resources :orden_items, controller: 'presupuestos/ordenes/orden_items'
end
end
Upvotes: 0
Views: 478
Reputation: 4653
I think I've found the problem.
Here is the updated Repo. I haven't tested it since I haven't Postgres
installed on this machine.
The problem was a problem with the directory.
Your controller is nested into the Presupuestos::Ordenes
module but the file was located in app/controllers/presupuestos/orden_items/
. Since rails' Autoload
feature expect that the file is located in app/controllers/presupuestos/ordenes/
it can't find it.
Just pull the changes of the Repo or rename the folder by yourself. app/controllers/presupuestos/orden_items/
=> app/controllers/presupuestos/ordenes/
Upvotes: 1