Same model multiple times, dynamically, in one form?

I just can’t seem to figure this out. I can do this no problem using
each_with_index and iterating through an array set up in the
controller’s “New.” But that only allows me to finite number of
records. I’d like for the user to be able to dynamically pick the
number records just by clicking “Add Another.”

Ryan B. walks us through a similar problem in his Complex Forms
series, specifically episode 2. However, that example is for 2 models
in the one form (one model is nested). My form is just the 1 model
but many times. This seems so simple, but I can’t figure it out. If
I use his javascript helper method and pass in the variables to the
partial, the input fields end up getting labeled the same as the
fields I generated by iterating through my New array (i.e. all of the
the fields are model[0][model_attribute]). I don’t know how to
increment the [0] using client side only javascript.

So any ideas?

Also, is this even the best way to solve this problem? I know there’s
a slightly different method in the Advanced Rails Recipes book, again
by Mr. Bates, but I can’t seem to adapt that to use the “add another”
javascript.

This seems like it’d be a common problem, 1 model many times
(dynamically) in 1 form, but haven’t been able to find enough out
there to solve my problem. Any ideas? Am I even going about this the
right way? Or, is there a better way?

Any help is greatly appreciated.

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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.