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 trialMarcela Jackowski
2,045 PointsWe need to populate our page with the list of pets. For this first task, use the each method in ERB tags to loop over ea
Can I get some help? I can't seem to answer this question. Thanks
<% @pets.each do |pet| %>
<p> <%= pet.all %></p>
<% end %>
3 Answers
Jay McGavren
Treehouse TeacherYou're close! Now that you've set up your each
loop, the pet
variable contains the current Pet
object. The problem is that you're calling a method named all
on the Pet
object, but the Pet
class doesn't have an all
method. Instead, you need to call the name
method on the Pet
object.
martinaraignee
12,786 PointsCouldn't ask for better explanation. Thank you
Muhammad sharifi
4,455 Pointsthis works <% @pets.each do |pet| %> <p><%= pet.name %> </p> <% end %> please mark as the accepted answer.
martinaraignee
12,786 Pointsmartinaraignee
12,786 Pointsdoes not accept. Could you please explain why not
Jay McGavren
Treehouse TeacherJay McGavren
Treehouse Teachermartinaraignee
pets
is an array ofPet
objects. The array does not have aname
method. ThePet
objects within the array each have aname
method, though. Theeach
method assigns eachPet
object to thepet
variable, one at a time. So you need to callpet.name
, notpets.name
.It's important to understand how the
each
method works before you go on. Make sure you've viewed the course's prerequisites, especially our Ruby Loops course.