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

Reply via email to