Forum: Ruby on Rails Removing "is invalid" msgs in validates_associated

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2007-03-21 22:07

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?

Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2007-03-21 22:23
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)

This topic is locked and can not be replied to.