# Link\_to\_remote and forms

**URL:** <https://www.ruby-forum.com/t/link-to-remote-and-forms/82080>\
**Category:** Rails\
**Created:** [January 17, 2007, 8:54am UTC](https://www.ruby-forum.com/t/link-to-remote-and-forms/82080 "2007-01-17T08:54:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![williamtaft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@williamtaft](https://www.ruby-forum.com/u/williamtaft)\
**Post date:** [January 17, 2007, 8:54am UTC](https://www.ruby-forum.com/t/link-to-remote-and-forms/82080/1 "2007-01-17T08:54:23Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![williamtaft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@williamtaft](https://www.ruby-forum.com/u/williamtaft)\
**Post date:** [January 18, 2007, 3:09am UTC](https://www.ruby-forum.com/t/link-to-remote-and-forms/82080/2 "2007-01-18T03:09:46Z")

</div>

can anyone help here?

---

<div class="post-metadata">

**Author:** ![williamtaft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@williamtaft](https://www.ruby-forum.com/u/williamtaft)\
**Post date:** [January 18, 2007, 5:37am UTC](https://www.ruby-forum.com/t/link-to-remote-and-forms/82080/3 "2007-01-18T05:37:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![williamtaft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@williamtaft](https://www.ruby-forum.com/u/williamtaft)\
**Post date:** [January 18, 2007, 6:07am UTC](https://www.ruby-forum.com/t/link-to-remote-and-forms/82080/4 "2007-01-18T06:07:33Z")

</div>

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>
> ```
