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 Routes to Create Actions Route for New Pets

Add a route that sends all GET requests for the /pets/new path to the PetsController's new action method.

I am not able to find an answer for this problem. Thanks.

Add a route that sends all GET requests for the /pets/new path to the PetsController's new action method.

routes.rb
Rails.application.routes.draw do
  get '/pets/new', to: 'pets#new'
end

1 Answer

Abdullah Hashim
Abdullah Hashim
4,546 Points

Hello,

I'm not really sure what you're asking but for the challenge you need two routes one for '/pets/:id' and another for '/pets/new'. The '/pets/new' route has to appear first, otherwise Rails will think that 'new' is an id.

Here is my solution

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