Ruby Active Record Associations in Rails Using Associations in Your App Rendering Collections

Brad Givens
Brad Givens
6,621 Points

Active record association

Really struggling with this challenge, the error message that appears seems indecipherable! I've tried various iterations and reviewed the video over again but I must still be missing something - any help would be amazing!

app/views/owners/show.html.erb
<h1>Owner: <%= @owner.name %></h1>

<div id="pets">
  <h2>Pets</h2>
    <%= @owner.name.each do |name| %>
  <%= render partial: "pets/pet", locals: {pet: pet} %>
  <% end %>

</div>
app/views/pets/_pet.html.erb
<div>
  <strong>Name:</strong>
  <%= name.content %>
</div>

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 46,156 Points

Hey Brad,

You want to call each on pets attribute associated with @owner, not the name attribute. Then within the partial you need to access the name attribute for the pet. There is no content attribute.

Brad Givens
Brad Givens
6,621 Points

Hey Clayton,

Thanks for the reply! So within the partial it should ready <%= pet.name %> as opposed to <%= name.content %>?