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:
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
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?