Return to Snippet

Revision: 1338
at September 27, 2006 12:58 by gdonald


Updated Code
# config/environment.rb
require "#{RAILS_ROOT}/app/overrides/all"

# app/overrides/all.rb
Dir[ File.dirname( __FILE__ ) + "/**/*.rb" ].each { |file| require( file ) }

# app/overrides/active_record.rb
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

Revision: 1337
at September 27, 2006 12:57 by gdonald


Initial Code
# config/environment.rb
require "#{RAILS_ROOT}/app/overrides/all"

# app/overrides/all.rb
Dir[ File.dirname( __FILE__ ) + "/**/*.rb" ].each { |file| require( file ) }

# app/overrides/active_record.rb
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

Initial URL


Initial Description


Initial Title
Rails active record single error patch

Initial Tags
error

Initial Language
Ruby