Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove ActiveModel::Errors#add_on_present method.

We don't need to define a new method in ActiveMode::Errors for each
validatior.

See
d72a07f#commitcomment-2325333
  • Loading branch information...
commit b437053b5b5c04712b9bf851353d08cff0600430 1 parent 8ee1c26
@rafaelfranca rafaelfranca authored
View
13 activemodel/lib/active_model/errors.rb
@@ -328,19 +328,6 @@ def add_on_blank(attributes, options = {})
end
end
- # Will add an error message to each of the attributes in +attributes+ that
- # is present (using Object#present?).
- #
- # person.errors.add_on_present(:name)
- # person.errors.messages
- # # => { :name => ["must be blank"] }
- def add_on_present(attributes, options = {})
- Array(attributes).flatten.each do |attribute|
- value = @base.send(:read_attribute_for_validation, attribute)
- add(attribute, :not_blank, options) if value.present?
- end
- end
-
# Returns +true+ if an error on the attribute with the given message is
# present, +false+ otherwise. +message+ is treated the same as for +add+.
#
View
4 activemodel/lib/active_model/validations/absence.rb
@@ -2,8 +2,8 @@ module ActiveModel
module Validations
# == Active Model Absence Validator
class AbsenceValidator < EachValidator #:nodoc:
- def validate(record)
- record.errors.add_on_present(attributes, options)
+ def validate_each(record, attr_name, value)
+ record.errors.add(attr_name, :not_blank, options) if value.present?
end
end
View
2  activemodel/lib/active_model/validator.rb
@@ -110,7 +110,7 @@ def initialize(options)
# Return the kind for this validator.
#
# PresenceValidator.new.kind # => :presence
- # UniquenessValidator.new.kind # => :uniqueness
+ # UniquenessValidator.new.kind # => :uniqueness
def kind
self.class.kind
end

0 comments on commit b437053

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