# Problems with incrementing and multiple submits

**URL:** <https://www.ruby-forum.com/t/problems-with-incrementing-and-multiple-submits/127438>\
**Category:** Rails\
**Created:** [January 29, 2008, 6:36am UTC](https://www.ruby-forum.com/t/problems-with-incrementing-and-multiple-submits/127438 "2008-01-29T06:36:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 29, 2008, 6:36am UTC](https://www.ruby-forum.com/t/problems-with-incrementing-and-multiple-submits/127438/1 "2008-01-29T06:36:20Z")

</div>

Hi,

Can someone help me with the following questions. I am trying to create  
a link\_to\_remote link named add. Whenever I click add, a new label and  
text field will be populated.

Example:

(This is already there)  
Book 1 text\_field add(this is the link)  
…when add is clicked…  
…the following is populated…

Book 2 text\_field

My question is how do I increment the number? How do I submit the  
various fields, populated and the one that is already there, that are in  
the form ? I read some where that it has to do with the id of the field.

This is my controller

def book  
@book = Book.new  
end

def save\_book  
@book = Book.new(params[:book])  
if @book.save  
redirect\_to :action =\> ‘some\_page’  
else  
render :action=\> ‘book’  
end  
end

def add\_book  
@count = 1  
render(:partial =\> ‘additional\_book’)  
end

This is my view

…\_additional\_book.rhtml…

Book \<%= @count %\> \<%= text\_field :book, :book, :id =\> @count %\>

…book.rhtml…

\<% form\_for :book, :url =\> { :action =\> :save\_book}, :html =\> { :id =\> "book" } do |n| %\> 

```
</tr>
<tr>
  <td style="width: 209px;">
    <div id="button">
<p><%= link_to_function 'Previous', "$('book').submit()" -%></p>
    </div>

```

| Book 0 | \<%= n.text\_field :book %\> \<%= link\_to\_remote( "add", :update =\> "abc", :url =\>{ :action =\> :add\_book }, :position =\> "bottom", :success =\> "@count ++") %\> |

\<% end %\>

Thanks
