To use a custom local variable name within the partial, specify the
:as option in the call to the partial:
With this change, you can access an instance of the
@products collection as the
item local variable within the partial.
You can also pass in arbitrary local variables to any partial you are rendering with the
In this case, the partial will have access to a local variable
title with the value “Products Page”.
Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by
_counter. For example, if you’re rendering
@products, within the partial you can refer to
product_counterto tell you how many times the partial has been rendered. This does not work in conjunction with the