# Noob: Validation Errs Don't Display When Saving Object Tree

**URL:** <https://www.ruby-forum.com/t/noob-validation-errs-dont-display-when-saving-object-tree/61316>\
**Category:** Rails\
**Created:** [May 23, 2006, 3:34am UTC](https://www.ruby-forum.com/t/noob-validation-errs-dont-display-when-saving-object-tree/61316 "2006-05-23T03:34:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![donncha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90db22/32.png) [@donncha](https://www.ruby-forum.com/u/donncha)\
**Post date:** [May 23, 2006, 3:34am UTC](https://www.ruby-forum.com/t/noob-validation-errs-dont-display-when-saving-object-tree/61316/1 "2006-05-23T03:34:07Z")

</div>

I’ve got the following model:

User \< AR::Base  
has\_one :user\_detail

UserDetail \< AR::Base  
belongs\_to :user  
has\_one :address

Address \< AR::Base  
belongs\_to :user\_detail

I’ve a form to gather the data, and it includes partials for each class.  
Each partial has an error\_messages\_for ‘class’ snippet which should  
display the errors relevant to each class.  
On submission I’m doing:

@user = User.new(params[:user])  
@user.user\_detail = UserDetail.new(params[:user\_detail])  
@user.user\_detail.address = Address.new(params[:address])

If I complete the form, all is well and the object tree gets saved  
correctly to the DB. However, if I deliberately omit key information  
from the form, only errors relevant to the User class are displayed. The  
User.save succeeds even if UserDetail or Address validations fail.

I thought that a save would fail if any of the objects on the model tree  
failed validation, and that all saves are transactional, so if one  
element failed the whole object tree got rolled back?

How can I ensure that  
a) a validation failure in either UserDetail or Address causes a  
rollback of the save  
b) validation errors in UserDetail and/or Address get displayed in the  
form?

thanks,  
donncha
