Reputation: 43
I've been going through the ruby on rails guide but I noticed something that I cant seem to understand. At the section where it teaches you how to render a partial form for the comment section of the blog. For the partial comments, they used
<h2>Comments</h2>
<%= render @article.comments %>
but for the form they used
<h2>Add a comment:</h2>
<%= render "comments/form" %>
Why is it that the first one used @article and not render "/comments"
Upvotes: 0
Views: 54
Reputation: 1202
It is because it will render the comments partial for each comment on the article object. It's like a 'for' loop without having to know the count of the comments, RAILS takes care of that.
For example: If an article has 2 comments it will render the partial twice.
You can read more about object associations in rails documentation.
Upvotes: 0