Getting an index of an element rendered in partial

The index of the element in the collection for :partial => 'foo' is a local variable foo_counter available within the partial.

However, you might consider using the element's id as the basis for linking.

Also, you could render :partial => 'partial', :collection => @elements.first(3)

You can also pass arbitrary variables into a partial with :locals => { :bar => 'iron' } which makes a local named bar available to the partial with a value of 'iron'.

If you have the Agile Web Development with Rails, 2nd ed., see Ch.22: Action View, "Layouts and Components" pp.509-511 (PDF pp.510-512).

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com