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 trialyanchung cheng
11,640 PointsFinding A Model Object
Not sure what is up with this.
Instruction - We've set up the following in routes.rb: get '/pets/:id', to: 'pets#show' But that controller action method doesn't exist yet. Create it now. Within the method, use the :id parameter to find the matching Pet record, and assign the result to the @pet instance variable.
Error - Bummer! NameError: undefined local variable or method `pets' for PetsController:Class Did you mean? puts Restart Get Help Recheck work
My Answer - class PetsController < ApplicationController
@pet = Pet.find(pets[:id]) end
2 Answers
JUN MENG
10,249 Points def show
@pet = Pet.find(params[:id])
end
Gabriel Carreau
8,738 PointsYou're not defining a show method, I just had the same problem!
def show
*code*
end
Adriana Cabrera
14,618 PointsAdriana Cabrera
14,618 PointsYou were very close, you just need to add params. I had the same issue and later I was able to figure out. I am glad we were able to figure out and continue with our journey.
def show @pet = Pet.find(params[:id]) end