Link_to_remote and forms

I want to have a form that adds new groups of the same input fields via
link_to_remote. I then want to collect those groups and insert them all
into the database.
So if I have a database that’s for groups of flashcards, with the card
id as the primary key, then I want to gather up the groups and insert
them at one time, looking something like this.

<%=link_to_remote("add Flash Card!", :url => {:action => "addAnotherCard"}) %>

#this will update the “deck div”

  <div class="deck">

#adds a card partial from an rjs template

           <div class="card">
             question: <input name="Deck[question]" />
             answer: <input name="Deck[answer]" />
           </div>

#adds another card etc…

           <div class="card">
             question: <input name="Deck[question]" />
             answer: <input name="Deck[answer]" />
           </div>
 </div>

I don’t have any problems adding the input fields, but I’m looking for a
way to identify the “card divs” with unique id’s, for if I wanted to
remove the elements, and I’m also trying to figure out how to get these
redundant fields in the database through one form. I’m looking around
to see if I can increment and assign a number id to the card div each
time a card is added, but no luck so far.

any help would be great!

can anyone help here?

Hi Sean,

Briefly, you need to pass the collection of cards into a view (like
list.rhtml) and within that view iterate through the collection and
generate
a partial for each card. Keep track of the ‘card number’ and use it to
assign the divs’ ids. So your partial will have a line like…

class='card'>

Got to run for now. Holler back if you need more help.

ill

Bill W. wrote:

Hi Sean,

Briefly, you need to pass the collection of cards into a view (like
list.rhtml) and within that view iterate through the collection and
generate
a partial for each card. Keep track of the ‘card number’ and use it to
assign the divs’ ids. So your partial will have a line like…

class='card'>

Slight alteration in case you have multiple classes that may be
manipulated:

You will also need to tag the input fields with different id’s so they
don’t stomp on each other (do this in your partial), eg:

           <div id="card-1" class="card">
             question: <input name="Deck[1][question]" />
             answer: <input name="Deck[1][answer]" />
           </div>

           <div id="card-2" class="card">
             question: <input name="Deck[2][question]" />
             answer: <input name="Deck[2][answer]" />
           </div>