Why do rails work partially in half?

I call partial in one of my views like this:

<%= render :partial => 'events/attendees', :collection => @attendees %>

partial, however, for some reason works twice ... here is partial:

<% @attendees.each do |user| %>

    <li><%= link_to user.name, user %></li>

<% end %>

and I checked that the rails actually do this partial twice, because in the output each element is displayed from @attendees twice

+3
source share
1 answer

This is because one “loop” from Rails ( :collectionmeaning that Rails will display a partial for each element in the collection, in this case @attendees) and one loop through your own partial.

Change the partial below (not sure about visitor / user relationship, but here is a sample):

<li><%= link_to attendee.name, attendee.user %></li>

Or change the partial call to:

<%= render :partial => 'events/attendees' %>
+8
source

All Articles