Forum: Ruby on Rails has_many before saving record

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.
Matt (Guest)
on 2007-06-07 23:09
(Received via mailing list)
I am currently creating a small app that can be simplified as follows:

An Album that has_many AlbumTracks
An AlbumTrack that belongs_to an Album

The user will create a new album - that is - not currently saved in
the database.
They will then add tracks to the album with an inline form that will
update the existing display, appending the track to the list of
tracks.

It is important that the Album record has not yet been saved for
usability purposes, as the user may decide to abort the creation,
which could be as simple as closing their browser, and incomplete
albums should not be stored in the database.

Additionally, during track insertion, the user must be able to reorder
the tracks, using the sortable_element scriptaculous helper. Again
before the saving of the record.

My thoughts on implementing this have been to use a session array to
store the track listings in, and then copying this tracklist array to
the main Album object on save/update. Is this the best way to achieve
this?

I am aware that I could simply use an html text_field array, which
would be fine for the initial insertion of the content, but could
potentially cause problems on an edit, whereby certain Tracks may have
been allocated an ID in the database from a previous save, and new
Tracks will not have an allocated ID.

Does anyone have any thoughts on this, or better still - a
solution! :)

Kind Regards,

Matt

p.s. the actual webapp is not an album and tracklist project, but that
is probably the simplest way I can describe my requirement - please
dont point me to the album/tracklist howto, as its not relevant!
This topic is locked and can not be replied to.