Skip to content
This repository
Browse code

Use .add instead of << to add errors

  • Loading branch information...
commit c317419359d9d868c4e8c12a2ba2e2f541eef3d6 1 parent c568a9b
Ev Dolzhenko dolzenko authored
4 activemodel/lib/active_model/validations/validates.rb
@@ -27,7 +27,7 @@ module ClassMethods
27 27 #
28 28 # class EmailValidator < ActiveModel::EachValidator
29 29 # def validate_each(record, attribute, value)
30   - # record.errors[attribute] << (options[:message] || "is not an email") unless
  30 + # record.errors.add attribute, (options[:message] || "is not an email") unless
31 31 # value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
32 32 # end
33 33 # end
@@ -48,7 +48,7 @@ module ClassMethods
48 48 #
49 49 # class TitleValidator < ActiveModel::EachValidator
50 50 # def validate_each(record, attribute, value)
51   - # record.errors[attribute] << "must start with 'the'" unless value =~ /\Athe/i
  51 + # record.errors.add attribute, "must start with 'the'" unless value =~ /\Athe/i
52 52 # end
53 53 # end
54 54 #
2  activemodel/lib/active_model/validations/with.rb
@@ -32,7 +32,7 @@ module ClassMethods
32 32 # class MyValidator < ActiveModel::Validator
33 33 # def validate(record)
34 34 # if some_complex_logic
35   - # record.errors[:base] << "This record is invalid"
  35 + # record.errors.add :base, "This record is invalid"
36 36 # end
37 37 # end
38 38 #
6 activemodel/lib/active_model/validator.rb
@@ -48,8 +48,8 @@ module ActiveModel #:nodoc:
48 48 #
49 49 # class MyValidator < ActiveModel::Validator
50 50 # def validate(record)
51   - # record.errors[:base] << "This is some custom error message"
52   - # record.errors[:first_name] << "This is some complex validation"
  51 + # record.errors.add :base, "This is some custom error message"
  52 + # record.errors.add :first_name, "This is some complex validation"
53 53 # # etc...
54 54 # end
55 55 # end
@@ -68,7 +68,7 @@ module ActiveModel #:nodoc:
68 68 #
69 69 # class TitleValidator < ActiveModel::EachValidator
70 70 # def validate_each(record, attribute, value)
71   - # record.errors[attribute] << 'must be Mr. Mrs. or Dr.' unless value.in?(['Mr.', 'Mrs.', 'Dr.'])
  71 + # record.errors.add attribute, 'must be Mr. Mrs. or Dr.' unless value.in?(['Mr.', 'Mrs.', 'Dr.'])
72 72 # end
73 73 # end
74 74 #

0 comments on commit c317419

Please sign in to comment.
Something went wrong with that request. Please try again.