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.
Written by Zeke Sikelianos
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Related Tags
#rails
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#