Possible Duplicate:
ActiveRecord: How can I clone nested associations?
I have a table with invoices which in turn can have many items.
Now in my invoices index view I would like to place a link next to each invoice saying Duplicate Invoice.
Without the child records this would be quite easy:
<%= link_to "Duplicate", new_invoice_path(invoice.attributes) %>
But how can this be done if the invoice's items should be duplicated as well?
As a Rails newbie I can't get my head around this. Can all this be handled by the new action inside my controller?
def new
@invoice = current_user.invoices.build(:project_id => params[:project_id])
@title = "New invoice"
end
Or do I need to create another function named e.g. copy inside my controller?
What is the best practice?
Thanks for any input...