Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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