rails 3 nested routing error
my routes.rb
TerritoryManagement::Application.routes.draw do
resources :addresses
resources :territories, :shallow => true do
resources :addresses
end
end
rake routes says
$ rake routes
addresses GET /addresses(.:format)
{:action=>"index", :controller=>"addresses"}
POST /addresses(.:format)
{:action=>"create", :controller=>"addresses"}
new_address GET /addresses/new(.:format)
{:action=>"n开发者_开发问答ew", :controller=>"addresses"}
edit_address GET /addresses/:id/edit(.:format)
{:action=>"edit", :controller=>"addresses"}
address GET /addresses/:id(.:format)
{:action=>"show", :controller=>"addresses"}
PUT /addresses/:id(.:format)
{:action=>"update", :controller=>"addresses"}
DELETE /addresses/:id(.:format)
{:action=>"destroy", :controller=>"addresses"}
territory_addresses GET /territories/:territory_id/addresses(.:format)
{:action=>"index", :controller=>"addresses"}
POST /territories/:territory_id/addresses(.:format)
{:action=>"create", :controller=>"addresses"}
new_territory_address GET /territories/:territory_id/addresses/new(.:format)
{:action=>"new", :controller=>"addresses"}
GET /addresses/:id/edit(.:format)
{:action=>"edit", :controller=>"addresses"}
GET /addresses/:id(.:format)
{:action=>"show", :controller=>"addresses"}
PUT /addresses/:id(.:format)
{:action=>"update", :controller=>"addresses"}
DELETE /addresses/:id(.:format)
{:action=>"destroy", :controller=>"addresses"}
territories GET /territories(.:format)
{:action=>"index", :controller=>"territories"}
POST /territories(.:format)
{:action=>"create", :controller=>"territories"}
new_territory GET /territories/new(.:format)
{:action=>"new", :controller=>"territories"}
edit_territory GET /territories/:id/edit(.:format)
{:action=>"edit", :controller=>"territories"}
territory GET /territories/:id(.:format)
{:action=>"show", :controller=>"territories"}
PUT /territories/:id(.:format)
{:action=>"update", :controller=>"territories"}
DELETE /territories/:id(.:format)
{:action=>"destroy", :controller=>"territories"}
in my list of territories I have the link
<td><%= link_to 'Show', new_territory_address_path %></td>
I get the error
No route matches {:controller=>"addresses", :action=>"new"} Extracted source (around line #14):
11: <% @territories.each do |territory| %>
12: <tr>
13: <td><%= territory.name %></td>
14: <td><%= link_to 'Show', new_territory_address_path %></td>
15: <td><%= link_to 'Delete', territory, :confirm => 'Are you sure?', :method => :delete %>
16: </tr>
17: <% end %>
What am I missing?
Thomas
Have you tried passing it a territory_id? Notice how it's included in the full route.
new_territory_address_path(:territory_id => territory.id)
精彩评论