# How do you display validation errors when validating child m

**URL:** <https://www.ruby-forum.com/t/how-do-you-display-validation-errors-when-validating-child-m/79957>\
**Category:** Rails\
**Created:** [March 11, 2006, 10:01pm UTC](https://www.ruby-forum.com/t/how-do-you-display-validation-errors-when-validating-child-m/79957 "2006-03-11T22:01:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryce\_Thornton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7993a0/32.png) [@Bryce\_Thornton](https://www.ruby-forum.com/u/Bryce_Thornton)\
**Post date:** [March 11, 2006, 10:01pm UTC](https://www.ruby-forum.com/t/how-do-you-display-validation-errors-when-validating-child-m/79957/1 "2006-03-11T22:01:19Z")

</div>

I can’t seem to figure out how to get child validation error messages  
to display. I’m going through the simple blog example DHH uses in his  
video. In the example, a comment belongs\_to a post. Validating posts  
works fine and the errors are displayed as they should be. When I try  
to validate a comment using:

validates\_presence\_of :summary

It does the proper validation by not inserting the comment, but the  
validation error message isn’t displayed when the controller  
redirects\_to the ‘show’ action. So, any ideas about how to get these  
child validations to display properly in the parent’s view?

Thanks,  
Bryce

---

<div class="post-metadata">

**Author:** ![Bryce\_Thornton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7993a0/32.png) [@Bryce\_Thornton](https://www.ruby-forum.com/u/Bryce_Thornton)\
**Post date:** [March 17, 2006, 12:44pm UTC](https://www.ruby-forum.com/t/how-do-you-display-validation-errors-when-validating-child-m/79957/2 "2006-03-17T12:44:11Z")

</div>

Did you ever get this sorted? I am struggling with a similar situation,  
and feeling particularly brain-dead at the moment.  
Chris T

---

<div class="post-metadata">

**Author:** ![Bryce\_Thornton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7993a0/32.png) [@Bryce\_Thornton](https://www.ruby-forum.com/u/Bryce_Thornton)\
**Post date:** [March 17, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/how-do-you-display-validation-errors-when-validating-child-m/79957/3 "2006-03-17T15:20:21Z")

</div>

Bryce Thornton wrote:

> I can’t seem to figure out how to get child validation error messages  
> to display. I’m going through the simple blog example DHH uses in his  
> video. In the example, a comment belongs\_to a post. Validating posts  
> works fine and the errors are displayed as they should be. When I try  
> to validate a comment using:
> 
> validates\_presence\_of :summary
> 
> Thanks,  
> Bryce

OK, with the help of an another thread got this sorted, so if you’re  
still struggling this is how I did it (though there’s prob better ways).

The problem (I think) is that I was svaing the parent-child relationship  
and with it the child. The child failed the validation but (and here I’m  
guessing) the error message was lost by the parent.save method. So I  
simply encased the parent.child save with an if child.valid? statement.  
Which threw me back to the form with the error messages and fields as  
before.

Except…[and I’m sure I saw the solution to this somewhere but can’t  
for the life of me find it now] the parent.id that was originally in the  
URL when the form was first visited (from a link: create a new child for  
this item), and was submitted with the other form items as a hidden  
field, is no longer there, and I can’t for the life of me think of an  
elegant way of keepiong in the form. Any ideas?

Chris T
