Let’s say I am going to render a collection of posts with a post partial.
<%= render collection: @posts, partial: "post" %>
module provides a couple handy methods when rendering collections.
I’ll have access in the partial template to
post_iteration) which will, in turn, give me access to
This is great if I need to do something special with the first or last item in the collection or if I’d like to do some sort of numbering based on the index of each item.
h/t Josh DaveyTweet