Overriding ActiveRecord Error Methods

Sometime you might find yourself wanting to customize the outputs from ActiveRecords errors. Here in an example of one way you could do just that:

module ActiveRecord
  class Errors
    ## ONLY RETURN THE 1ST ERROR FOR EACH ATTRIBUTE ##
    def first_messages
      list = []
      first_messages = []
      @errors.each_key do |attr|
        @errors[attr].each do |msg|
          next if msg.nil?
          if attr == "base"
            unless list.include? attr
              first_messages << msg
              list << attr
            end
          else
            unless list.include? attr
              first_messages << @base.class.human_attribute_name(attr) + " " + msg
              list << attr
            end
          end
        end
      end
      return first_messages
    end
  end
end