Forum: Ruby on Rails has_many - master detail page

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bfb4faac1ebe6bcd236d65cf98428632?d=identicon&s=25 reed (Guest)
on 2007-03-15 10:18
(Received via mailing list)
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?
<p>Line 1 Descrption<%= text_field 'invoice', 'lines[0].description'
%></p>
<p>Line 2 Descrption<%= text_field 'invoice', 'lines[1].description'
%></p>

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.
This topic is locked and can not be replied to.