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 A Route to a Read Action Creating a Show View

bessiebarnes
bessiebarnes
87,698 Points

I'm stuck again on a challenge. I need help.

The show action method on the PetsController includes the following code:

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

Add a level 1 heading (<h1>) element to the template. Within that element, embed the Pet's name attribute. I tried <h1><%= pet.name %></h1>

app/views/pets/show.html.erb
<%  @Pet.find(params[:id]) %>
<h1> <%= pet.name %></h1>
end
Oswaldo Rangel
Oswaldo Rangel
3,554 Points

Hi Bessie, when you are working on a view that's referenced by a controller you already have access to the instance variable in this case @pet so you don't need to call it from the view, the controller is doing that work for you :), and in order to render the name just get the name from the instance variable it self like this:

@pet.name and remove <% @Pet.find(params[:id]) %>

end from the view.

cheers and happy coding!

1 Answer

bessiebarnes
bessiebarnes
87,698 Points

the answer is <h1> <%= @pet.name %></h1> Thanks Oswaldo!