Forum: Ruby on Rails forms that mix new and old records

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.
9d12e24c0a3aebe28b58682d517acdfb?d=identicon&s=25 ybernet@msn.com (Guest)
on 2009-02-09 15:36
(Received via mailing list)
I'm trying to create a form/view that displays a mix of records that
exist in the database and records that the user is working on but that
don't yet exist in the database. I want to leverage all of rails' nice
form helpers, especially the params hash that it generates for the
records when the form is submitted. So - I am creating 'dummy' records
with fake ids to represent the new records that don't really exist in
the database.

I'm getting wrapped around the axle when I try and submit the form. I
need to identify the pre-existing records and just save them back to
the database with any modified data. For the new records, I need to
create them fresh and then save them to the database.

I've been trying all sorts of clever tricks to identify the new
records based on their fake ids, but I keep running into difficulties.
I'm wondering if there is a simple convention for handling this
scenario that I am missing, or if this is just one of those scenarios
that requires a lot of work to make it work properly.

Any guidance would be appreciated.

Yoram
9d12e24c0a3aebe28b58682d517acdfb?d=identicon&s=25 ybernet@msn.com (Guest)
on 2009-02-09 15:44
(Received via mailing list)
I should add that I feel that I have a reasonable mechanism for
identifying 'old' record ids vs. 'new' record ids. It works great
except for when the user uses the back button and resubmits the form.
So - perhaps what I really need is a mechanism for avoiding double-
submits.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-02-09 15:52
(Received via mailing list)
On Feb 9, 2009, at 9:43 AM, ybernet@msn.com wrote:
>> don't yet exist in the database. I want to leverage all of rails'
>> create them fresh and then save them to the database.
>> Yoram
Do your "fake" IDs all begin with something like 'new_'?

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.