Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Rails Routes and Resources A Route to a Read Action Set Up a URL Parameter

Trouble with 2nd code challenge for creating a route

The question is the following:

Set up a route to view an individual Pet. It should match GET requests with a path of /pets/ followed by the ID of the particular Pet: /pets/3, /pets/27, etc. You'll need to set it up so that the ID from the path is available within the controller as params[:id]. Matching requests should be routed to the show action method on PetsController

I feel like my code should be correct but i may be missing something.

I'm calling the http method get to the /pets/:id path where each pet can be called with the id parameter to: pets#show i.e. the pets controller with the show method.

Any help would be much appreciated!

routes.rb
Rails.application.routes.draw do
  get '/pets/:id' to: 'pets#show'
end

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Only a small issue here.

Between 'pets/:id' and 'pets#show', you need to have a comma as a separator there.

Rails.application.routes.draw do
  get '/pets/:id', to: 'pets#show'
end

hope it helps

Wow good eye thank you.