Unique identifier on render :partial with collection

Is there any way to pass a unique identifier to each iteration of a
partial generated using the :collection option?

I have a form that contains a variable number of text fields that
collect data into an array that’s processed in the controller upon
submit. A text field can be added to the form using an AJAX request
that adds a new blank object to a collection and re-renders the partial
using the new collection. The thing is, I need to be able to remove
text fields also, so they need to have a unique ID.

Is there some sort of unique identifier that is passed into the partial
when you’re using the :collection option?

Andrew

Andrew H. wrote:

Is there any way to pass a unique identifier to each iteration of a
partial generated using the :collection option?

I have a form that contains a variable number of text fields that
collect data into an array that’s processed in the controller upon
submit. A text field can be added to the form using an AJAX request
that adds a new blank object to a collection and re-renders the partial
using the new collection. The thing is, I need to be able to remove
text fields also, so they need to have a unique ID.

Is there some sort of unique identifier that is passed into the partial
when you’re using the :collection option?

Andrew

Nevermind! I just found the “free” _counter variable that is made
available to each iteration of the partial.

On Tue, 2007-10-16 at 00:21 +0200, Andrew H. wrote:

Is there some sort of unique identifier that is passed into the partial
when you’re using the :collection option?

Andrew

There is a counter by the name of <partial_name>_counter, so
render(:partial => ‘foo’, :collection => array) would have a
foo_counter.


Tore D.
[email protected]
Trondheim, NO
http://tore.darell.no/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs