Forum: Ruby on Rails Dynamic fields creation and accessing data

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
48e2f53bc3396f2633673907dd0d62ad?d=identicon&s=25 Naroor Rathish (naroor)
on 2005-12-20 07:06
Hi friends ,
   I was trying this code and finding some errors.I am trying this to
implement dynamic creation of invoice items in invoices using AJAX
.Please go thru .

 I added a partial ::
<% @invoiceitem = invoiceitem -%>
 <%= text_field 'invoiceitem', 'item_price', 'index' =>
 invoiceitem_counter %>
 <%= text_field 'invoiceitem', 'item_qty', 'index' =>
invoiceitem_counter
 %>
Where are we initialising the counter? Please tell how is the first line
working .

In the rhtml file I have added  :

    <%= form_remote_tag(:update => "my_list",
                       :url => { :action => :add_new_item },
                       :position => "bottom" ) %>

            <%= submit_tag "Add New Item" %>
       <%= end_form_tag %>
   <form action="/ajax/save_items" method="post">
    <ul id="my_list">
      <li>Original item... please add more!</li>
    </ul>

    <%= submit_tag 'Update' %>
   </form>
I have added like this for creating a dynamic generation of text boxes
using ajax.

And in the controller class ,

  def add_new_item

   render(:partial => 'invoiceitems', :collection => @invoice_items)

  end
  def save_items

	 @items = []
	params[:invoiceitem].each do |key, item|
		@items = InvoiceItem.new(item)
	end
   end

Please help my in implementing this requirement .

Thanks and regards,
Naroor Rathish.
This topic is locked and can not be replied to.