1

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=>"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"}

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

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

3 Comments

You could even just pass the territory object itself, Rails will know what you mean: new_territory_address_path(territory)
ok, thanks and why isn't this one working? territory_path(:territory_id => territory.id)
I have one more problem in this context. In my territory show view I'm rendering an address form, to be able to add addresses to a specific territory. So now with territory_path(territory) working it says ActionController::RoutingError in Territories#show No route matches {:controller=>"addresses"} and says it doesn't like this beginning of the partial <%= form_for @address do |f| %> What's wrong with that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.