Last Updated: September 09, 2019
·
1.111K
· zeke

Rails collections have a secret counter

Rails 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_counter to tell you how many times the partial has been rendered. This does not work in conjunction with the :as => :value option.