# Removing "is invalid" msgs in validates\_associated

**URL:** <https://www.ruby-forum.com/t/removing-is-invalid-msgs-in-validates-associated/89653>\
**Category:** Rails\
**Created:** [March 21, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/removing-is-invalid-msgs-in-validates-associated/89653 "2007-03-21T22:07:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 21, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/removing-is-invalid-msgs-in-validates-associated/89653/1 "2007-03-21T22:07:14Z")

</div>

All,

When using validates\_associated to cause cascading validation from my  
parent AR class into it’s children, by default a “\_\_\_\_\_ is invalid”  
message is added to the errors collection for the parent for each child  
object that isn’t valid.

I don’t want to display these messages, since I am generating new  
messages to stand in their place.

I am using the standard scaffolding error reporting scheme  
(errorExplanation div and fieldWithErrors around each field).

I can suppress these messages by setting :message =\> ‘’ or :message =\>  
nil on the validates\_associated, but what I really want to do is to  
remove the errors from the errors collection that are associated with  
the “is invalid” messages.

I tried this:

#Get rid of all of the annoying “is invalid” error messages and generate  
unique errors for the class codes  
old\_errors = @artisan\_quote\_input.errors.clone  
@artisan\_quote\_input.errors.clear  
old\_errors.each\_full do |msg|  
@artisan\_quote\_input.errors.add\_to\_base(msg) unless msg =~ /is  
invalid/ || @artisan\_quote\_input.errors.full\_messages.include?(msg)  
end

But then several of my fields no longer show up with red borders in my  
form.

Anybody have any experience with manipulating the ActiveRecord::Errors  
object in this way?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 21, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/removing-is-invalid-msgs-in-validates-associated/89653/2 "2007-03-21T22:23:14Z")

</div>

This works much better:

old\_errors = @artisan\_quote\_input.errors.clone  
@artisan\_quote\_input.errors.clear  
old\_errors.each do |attr, msg|  
@artisan\_quote\_input.errors.add(attr, msg) unless msg =~ /is invalid/  
|| @artisan\_quote\_input.errors.full\_messages.include?(msg)  
end

Thanks,  
Wes
