The problem is that I also need an index of every element in the array
inside the partial (to correctly create a link to it). Is there a way to
somehow determine an index of an element inside the partial or maybe to
somehow pass it along as separate variable?
inside the partial (to correctly create a link to it). Is there a
way to
somehow determine an index of an element inside the partial or
maybe to
somehow pass it along as separate variable?
Thanks in advance
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 D. with Rails, 2nd ed., see Ch.22:
Action View, “Layouts and Components” pp.509-511 (PDF pp.510-512).
I can’t use IDs, because the table is sorted by values from another
column and I need to paginate through this sorted table. But the
foo_counter is exactly what I need.
Thank you very much!
Rob B. wrote:
On Apr 25, 2007, at 1:59 PM, Szymon N. wrote:
inside the partial (to correctly create a link to it). Is there a
way to
somehow determine an index of an element inside the partial or
maybe to
somehow pass it along as separate variable?
Thanks in advance
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 D. with Rails, 2nd ed., see Ch.22:
Action View, “Layouts and Components” pp.509-511 (PDF pp.510-512).