On Sep 6, 6:06 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.
Well you've only got one form, so when you hit submit all of the
item_id, quantity and price parameters are submitted and in this case
when faced with a repeated parameter rails picks the last one. The
browser doesn't know that because you've hit the submit button for one
row you only want to submit those fields that are close to it.
Fred
> 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
-~----------~----~----~----~------~----~------~--~---