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 Finding a Model Object

yanchung cheng
yanchung cheng
11,640 Points

Finding 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

Adriana Cabrera
Adriana Cabrera
14,618 Points

You 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

2 Answers

  def show 
    @pet = Pet.find(params[:id])
  end

You're not defining a show method, I just had the same problem!

def show
*code*
end