Skip to content

Commit

Permalink
Use .add instead of << to add errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dolzenko committed Oct 11, 2011
1 parent c568a9b commit c317419
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions activemodel/lib/active_model/validations/validates.rb
Expand Up @@ -27,7 +27,7 @@ module ClassMethods
#
# class EmailValidator < ActiveModel::EachValidator
# def validate_each(record, attribute, value)
# record.errors[attribute] << (options[:message] || "is not an email") unless
# record.errors.add attribute, (options[:message] || "is not an email") unless
# value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
# end
# end
Expand All @@ -48,7 +48,7 @@ module ClassMethods
#
# class TitleValidator < ActiveModel::EachValidator
# def validate_each(record, attribute, value)
# record.errors[attribute] << "must start with 'the'" unless value =~ /\Athe/i
# record.errors.add attribute, "must start with 'the'" unless value =~ /\Athe/i
# end
# end
#
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/validations/with.rb
Expand Up @@ -32,7 +32,7 @@ module ClassMethods
# class MyValidator < ActiveModel::Validator
# def validate(record)
# if some_complex_logic
# record.errors[:base] << "This record is invalid"
# record.errors.add :base, "This record is invalid"
# end
# end
#
Expand Down
6 changes: 3 additions & 3 deletions activemodel/lib/active_model/validator.rb
Expand Up @@ -48,8 +48,8 @@ module ActiveModel #:nodoc:
#
# class MyValidator < ActiveModel::Validator
# def validate(record)
# record.errors[:base] << "This is some custom error message"
# record.errors[:first_name] << "This is some complex validation"
# record.errors.add :base, "This is some custom error message"
# record.errors.add :first_name, "This is some complex validation"
# # etc...
# end
# end
Expand All @@ -68,7 +68,7 @@ module ActiveModel #:nodoc:
#
# class TitleValidator < ActiveModel::EachValidator
# def validate_each(record, attribute, value)
# record.errors[attribute] << 'must be Mr. Mrs. or Dr.' unless value.in?(['Mr.', 'Mrs.', 'Dr.'])
# record.errors.add attribute, 'must be Mr. Mrs. or Dr.' unless value.in?(['Mr.', 'Mrs.', 'Dr.'])
# end
# end
#
Expand Down

0 comments on commit c317419

Please sign in to comment.