# Has\_many - master detail page

**URL:** <https://www.ruby-forum.com/t/has-many-master-detail-page/88885>\
**Category:** Rails\
**Created:** [March 15, 2007, 10:18am UTC](https://www.ruby-forum.com/t/has-many-master-detail-page/88885 "2007-03-15T10:18:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@reed](https://www.ruby-forum.com/u/reed)\
**Post date:** [March 15, 2007, 10:18am UTC](https://www.ruby-forum.com/t/has-many-master-detail-page/88885/1 "2007-03-15T10:18:41Z")

</div>

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.
