Ruby Active Record Associations in Rails Using Associations in Your App Nested Routes and Resources

bessiebarnes
bessiebarnes
53,174 Points

Help with Nested Routes Challenge. What am I doing wrong?

Challenge Task 1 of 1 Every Pet belongs to an Owner, so we want an owner_id parameter as part of the URL for all of our Pet routes:

Verb URI Pattern Controller#Action GET /owners/:owner_id/pets(.:format) pets#index POST /owners/:owner_id/pets(.:format) pets#create GET /owners/:owner_id/pets/new(.:format) pets#new GET /owners/:owner_id/pets/:id/edit(.:format) pets#edit GET /owners/:owner_id/pets/:id(.:format) pets#show PUT /owners/:owner_id/pets/:id(.:format) pets#update DELETE /owners/:owner_id/pets/:id(.:format) pets#destroy

Make the necessary changes here in config/routes.rb to set all of the above routes up. (You can set up routes for owners as well if you want, but we'll only be checking whether the above routes exist.)

Rails.application.routes.draw do resources :pets do get '/owners/:owner_id/pets(.:format)', to: 'pets#index', as: ‘pets’ post '/owners/:owner_id/pets(.:format)', to: 'pets#create', as: ‘create’ get '/owners/:owner_id/pets/new(.:format)', to: 'pets#new', as: 'new' get '/owners/:owner_id/pets/:id/edit(.:format', to: 'pets#edit', as: ‘edit’ get '/owners/:owner_id/pets/:id(.:format)', to: 'pets#show', as: ‘show’ put '/owners/:owner_id/pets/:id(.:format)', to: 'pets#update' delete '/owners/:owner_id/pets/:id(.:format)', to: 'pets#destroy'

end I'm getting error messages on my answer. Please help. What am I doing wrong?

2 Answers

Dimitri Fajardo
PRO
Dimitri Fajardo
Pro Student 6,973 Points
resources :owners do
  resources :pets
end

I don't know what your doing wrong but I would need to view your code to explain. I hope this helps!

Christopher Phillips
Christopher Phillips
10,050 Points

A misleading challenge. It says setting up Owners is optional yet the requirement to complete the challenge tells you that you must set up owners as shown by the paths that will be checked. I used the same code as Dimitri.