> You say to use a transaction... I already am using a transaction!

Sorry about that. I obviously didn't read carefully your post.

> The issue is that if the person save succeeds and the client save
> fails then the transaction is rolled back fine. However the person
> record now has a person.id and subsequent code assumes that the record
> is saved and tries to refind the record which of course does not
> exist.
>
> I have got around this by saving the original value of the person.id
> and then resetting it in the rescue clause but it is a bit messy.
>
> One other issue is that the only validation errors that get set are
> the errors from the first record (person) that is saved so the user
> may fix these up only to find new validation errors from the second
> record...

I have not tried before what you are trying to do but I will as soon
as I have some time to spare. I don't understand why Rails would not
clear the ID value of the record and reset the record in order for
new_record? to return true.

> I'm sure there must be a tidy way!

If you use acceptes_nested_attributes_for and field_for the
validations will work just like you want them to work, however you
will need to change your form to be based on your person model, which
based on what you have explained would be pretty much impossible since
the person is selected in the form and you don't have a person object
to base the form on.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to