Has_many - master detail page

I am trying to figure out a correct way to do master detail type pages
with Rails. All the online demos I could find that had two tables in
one post were habtm and they are not close enough to be useful.

Say we wanted a page for creating/editing an invoice which allowed us
to edit the invoice header and the invoice_lines on the same page.

In the rhtml file how should the invoice_lines input fields be
generated.
Do I have to do something like the following (which doesn’t work as
is) and them iterate through and save each invoice_line individualy?

Line 1 Descrption<%= text_field 'invoice', 'lines[0].description' %>

Line 2 Descrption<%= text_field 'invoice', 'lines[1].description' %>

How should the post save the lines, is there a way for the invoice
save to save the invoice_lines at the the same time in the same way
the habtm relationship does?

I can think of a number of ways of achieving the above but none of
them are tidy. I must be missing something. Most of the solutions I
have come up with require the invoice header to be commited first on a
previous page or action.

Any help appreciated.