Problems with incrementing and multiple submits

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

user splash wrote:

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)

Hi,

Any help for the above questions will be appreciated.

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs