1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class ActiveRecord::Errors
  alias old_full_messages full_messages
  def full_messages
    old_full_messages.uniq
  end
end

module ActiveRecord::Validations::ClassMethods
  def validates_associated(*associations)
    associations.each do |association|
      class_eval do
        validates_each(associations) do |record, associate_name, value|
          associates = record.send(associate_name)
          associates = [associates] unless associates.respond_to?('each')
          associates.each do |associate|
            if associate && !associate.valid?
              associate.errors.each do |key, value|                
                record.errors.add(key, value)       
              end
            end
          end
        end
      end
    end
  end
end