OK, I have a routing problem, that seems to be working in the console,
and with rake routes but not in the app.
I have people that have nested tasks, like so:
routes.rb
map.resources :people do |person|
person.resources :phone_notes
person.resources :documents
person.resources :tasks, :member => {:complete => :put}
end
map.resources :tasks, :member => {:complete => :put}
And then if I go into irb and try to recognize and generate those
routes, all is good:
rs = ActionController::Routing::Routes
rs.recognize_path(“/people/9/tasks/95/complete”, :method => :put)
=>
{:action=>“complete”, :person_id=>“9”, :controller=>“tasks”, :id=>“95”}
rs.generate({:action=>“update”, :person_id=>“9”,
:controller=>“tasks”, :id=>“95”})
=> “/people/9/tasks/95/complete”
So that is all good.
Then rake routes gives me a list which also shows things are good:
complete_person_task PUT /people/:person_id/tasks/:id/complete
{:controller => “tasks”, :action => “complete”}
But then in my people/show view I have:
<%= button_to “Done”, :url => complete_person_task_path(task), :method
=> :put -%>
Which generates this URL:
http://127.0.0.1:3000/people/9?method=put&url=%2Fpeople%2F9%2Ftasks%2F95%2Fcomplete
Which gives the following error:
Unknown action
No action responded to 9
So obviously the route is not tagging on the custom nested route I
have made.
So I disabled the “default” routes at the bottom and then I get:
ActionController::MethodNotAllows
Only get, put, and delete requests are allowed
Request Parameters:
{“url”=>“/people/9/tasks/95/complete”,
“method”=>“put” }
Anyone got any ideas? I am sure it is something simple, but just
tearing my hair out on this one.
Regards
Mikel