Matteo Pagliazzi
Matteo Pagliazzi

Reputation: 5270

Rails nested resources and paths

in my routes.rb I have:

  resources :boards do
    resources :items
  end

now in boards#show I want to show a link to http://mysite/baord/:board_id/items/new, running rake routes I get:

new_board_item GET    /boards/:board_id/items/new(.:format)                        items#new

and so I should be able to use new_board_item_path but this works only from site.com/board/:board_id/items but i want to use this link in boards#show action but it tells me that:

No route matches {:action=>"new", :controller=>"items"}

while that's not true!

Upvotes: 1

Views: 289

Answers (1)

Joe Pym
Joe Pym

Reputation: 1836

Pass the parent resource into the path, so in this case:

new_board_item_path(@board)

Upvotes: 1

Related Questions