2011-08-25 192 views
1

我的routes.rb軌道3嵌套路由錯誤

TerritoryManagement::Application.routes.draw do 
    resources :addresses 
    resources :territories, :shallow => true do 
    resources :addresses 
    end 
end 

耙路線說

$ rake routes 
     addresses GET /addresses(.:format) 
{:action=>"index", :controller=>"addresses"} 
        POST /addresses(.:format) 
{:action=>"create", :controller=>"addresses"} 
     new_address GET /addresses/new(.:format) 
{:action=>"new", :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"} 

在我的領土名單上有鏈接

<td><%= link_to 'Show', new_territory_address_path %></td> 

我得到的錯誤

沒有路線匹配{:controller =>「地址」:動作=> 「新」} 提取的源(左右線#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 %> 

我缺少什麼?

Thomas

回答

1

您是否嘗試過將它傳遞給territory_id?注意它是如何包含在完整路線中的。

new_territory_address_path(:territory_id => territory.id) 
+0

你甚至可以只通過境內對象本身,Rails會知道你的意思是:'new_territory_address_path(境)' – skorks

+0

好的,謝謝,爲什麼沒有這樣一個工作? territory_path(:territory_id => territory.id) – Thomas

+0

這個工作雖然territory_path(領土) – Thomas