Forum: Ruby on Rails Automatic inclusion of child errors in validation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andre B. (Guest)
on 2005-11-18 14:34
Here are the pertinent bits of the model classes I'm having an issue
with...

# BEGIN CODE

class User < ActiveRecord::Base
    has_many :contacts, :order => :position

    # This allows me to collect up the individual errors for each
subclass of
    # Contact I use (EmailAddress, PhysicalAddress, PhoneNumber)
    def after_validation
        contacts.each { |c| c.errors.each { |attr, msg|
errors.add(Inflector.underscore(c.class), msg) } }
    end

    # One of the virtual attributes for reference
    def email_address
        address = contacts.detect { |c| c.is_a?(EmailAddress) }
        address ? address.content : nil
    end

    # - and its setter method
    def email_address=(content, description = nil)
        address = contacts.find(:first, :conditions => ["type =
'EmailAddress' AND content = ?", content])
        address.move_to_top and return if address

        address = EmailAddress.new(:description => description, :content
=> content)
        contacts << address
        address.save and address.move_to_top unless @new_record
    end
end

class Contact < ActiveRecord::Base
    acts_as_list :scope => :user_id
    belongs_to :user
end

# One of the Contact subclasses for reference
class EmailAddress < Contact
    validates_format_of :content, :with =>
/^[a-z0-9\-_\.]+@[a-z0-9\-\.]+$/
end

# END CODE

Ever since switching from the 0.13.x stream to the 0.14.x stream I am
now getting extra errors when (for example) an e-mail address doesn't
validate. The quickest way to describe this change is that it is now as
though an implicit 'validate_association :contact' has been added to my
User class just because an EmailAddress is a subclass of Contact of
which User has many. What has been changed and how can I override it so
that my error messages aren't full of 'Contacts is invalid' rubbish?
This topic is locked and can not be replied to.