Showing errors for saves of 2 records

I accept input for two related records from a user form and in my
controller I do the following:

Record1.transaction do
Record1.save!
Record2.save!
end

Record2 is related to record1, and can only be saved if Record1 is
saved. Now obviously if the user entered some invalid input for
Record1, then the verification on save of Record1 will fail.
Unfortunately, because of this Record2.save isn’t called, and I don’t
have any information on whether the user’s input for Record2 is valid.
As a result, when the user gets kicked back to the form, they only see
errors related to Record1 input. They may fix all of that, press
submit again, and then see new errors for the Record2 save.

This is no good, of course. I need to be able to show errors to the
user for the input related to both Record1 and Record2. How can I do
this?

Thanks,
Garth

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs