Maybe something like this in your create action:
def create
@invoice = Invoice.new(params[:invoice]
#find duplicate invoice (if exists)
duplicate_invoice = Invoice.find(params[:duplicate_invoice_id])
unless duplicate_invoice.nil?
items = nil
duplicate_items = duplicate_invoice.items
duplicate_items.each do |child|
item = Item.new(child.attributes)
item.save
items << item
end
end
if @invoice.save
@invoice.items << items #add the duplicate items to the duplicate invoice
#handle your redirects....
end
end
Essentially what you can do pass the id of the duplicate invoice to your create action, find the invoice that you intent to duplicate and then process it's children items into an array of duplicate items. The final step is to add those newly duplicated items to your newly duplicated invoice. This is obviously untested and it's going to require a little additional work on your end but I hope you get the gist of the idea. There's probably other ways to accomplish this.
Of course, there are also gems that can do this for you but it's your call.