rails/rails — Issue #4505: Nested routes for create action are not working
Author: daniel2d2art
Created: 2012-01-17 20:10:08+00:00
State: open

RoR 3.1.3

With routes:
resources :foo do
resources :bar
end
resources :bar

generates :

[...]
foo_bars GET /foos/:foo_id/bars(.:format) {:action=>"index", :controller=>"bars"}
POST /foos/:foo_id/bars(.:format) {:action=>"create", :controller=>"bars"}
new_foo_bar GET /foos/:foo_id/bars/new(.:format) {:action=>"new", :controller=>"bars"}
edit_foo_bar GET /foos/:foo_id/bars/:id/edit(.:format) {:action=>"edit", :controller=>"bars"}
foo_bar GET /foos/:foo_id/bars/:id(.:format) {:action=>"show", :controller=>"bars"}
PUT /foos/:foo_id/bars/:id(.:format) {:action=>"update", :controller=>"bars"}
DELETE /foos/:foo_id/bars/:id(.:format) {:action=>"destroy", :controller=>"bars"}
[...]

You can see above:
POST /foos/:foo_id/bars(.:format) {:action=>"create", :controller=>"bars"}

With the url helper:
foo_bars_path(125131)

You get:
http://localhost:3000/foos/125131/bars

But if you send a POST request to the above url:
http://localhost:3000/foos/125131/bars
Gets a 404 Error because the next error:
"The action '125131' could not be found for foosController"

Testign for other route like gets a nested entity works properly, for example:
foo_bars GET /foos/:foo_id/bars(.:format) {:action=>"index", :controller=>"bars"}
http://localhost:3000/foos/125132/bars/32170 (GETs the 32170 bar item of 125132 foos correctly)