> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/where-am-i-in-the-partial-iteration.md).

# Where Am I In The Partial Iteration?

Let's say I am going to render a collection of posts with a post partial.

```erb
<%= render collection: @posts, partial: "post" %>
```

The [`ActionView::PartialIteration`](http://api.rubyonrails.org/classes/ActionView/PartialIteration.html) module provides a couple handy methods when rendering collections. I'll have access in the partial template to `#{template_name}_iteration` (e.g. `post_iteration`) which will, in turn, give me access to `#index`, `#first?`, and `#last?`.

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.

[source](http://stackoverflow.com/questions/13397848/rails-render-collection-partial-getting-size-of-collection-inside-partial)

h/t Josh Davey


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/rails/where-am-i-in-the-partial-iteration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
