Removing "is invalid" msgs in validates_associated



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
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)

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

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



This works much better:

old_errors = @artisan_quote_input.errors.clone
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)