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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Hite
2007-Oct-15 22:32 UTC
Re: Unique identifier on render :partial with collection
Andrew Hite 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? > > AndrewNevermind! I just found the "free" _counter variable that is made available to each iteration of the partial. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tore Darell
2007-Oct-15 22:33 UTC
Re: Unique identifier on render :partial with collection
On Tue, 2007-10-16 at 00:21 +0200, Andrew Hite 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? > > AndrewThere is a counter by the name of <partial_name>_counter, so render(:partial => ''foo'', :collection => array) would have a foo_counter. -- Tore Darell toredarell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Trondheim, NO http://tore.darell.no/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---