This article should clear it up. The core of it is that
<% render @post.comments %>
will do the same thing as
<% @post.comments.each do |comment| %>
<%= render partial: 'comments/comment', locals: { comment: comment } %>
<% end %>
Your variable comment
inside the partial template is declared by render
, triggered by the locals
hash. The article further explains the magic of how you get the latter from the former.