Your submit button is within the @items.each loop, hence I see that for each row there is an 'Add Item' button.There should be only 1 submit button in the end (if you want to submit the entire form)
Thanks & Regards, Dhruva Sagar. Joan Crawford<http://www.brainyquote.com/quotes/authors/j/joan_crawford.html> - "I, Joan Crawford, I believe in the dollar. Everything I earn, I spend." On Mon, Sep 7, 2009 at 12:29 PM, Abhinav Saxena <[email protected]>wrote: > I guess you should not use f.submit for "Add item", instead you should use > a link and a corresponding action which will add an item and render lineitem > form again. > > Thanks, > Abhinav > -- > अभिनव > http://twitter.com/abhinav > > > > On Sun, Sep 6, 2009 at 10:36 AM, maximulus <[email protected]> wrote: > >> >> Hello, >> >> I'm clearly missing some bit of code, but I can't figure out what. >> There are three models: Invoice, Lineitems and items. I want the user >> to search a list of items, and then add them to the lineitems table. >> The seach works, an provides a list on this form: >> >> >> <% form_for :lineitems, :url => {:action => 'create', :id=> >> @invoice.id} do |f|-%> >> <table> >> >> <% @items.each do |item| %> >> >> <tr> >> <td><%=item.itemname %></td> <%= >> f.hidden_field :item_id, :value=>item.id %> >> <td><%= f.text_field :quantity %></td> >> <td><%= f.text_field :price, :value => item.sellprice %></td> >> >> <td><%= f.submit 'Add Item' %> </td> >> </tr> >> <% end %> >> >> When you click 'Add Item', it submits for that last item on the list, >> not the corresponding item. >> >> Controller code for create is: >> @invoice = Invoice.find(params[:id]) >> >> @lineitems = @invoice.lineitems.new(params[:lineitems]) >> >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

