class ActiveModel::Errors
def added?(attribute, type = :invalid, options = {})
person.errors.added? :name, :too_long # => false
person.errors.added? :name, :too_long, count: 24 # => false
person.errors.added? :name, "is too long (maximum is 25 characters)" # => true
person.errors.added? :name, :too_long, count: 25 # => true
person.errors.add :name, :too_long, { count: 25 }
the correct options, or +false+ with incorrect or missing options.
If the error requires options, then it returns +true+ with
person.errors.added? :name, "can't be blank" # => true
person.errors.added? :name, :blank # => true
person.errors.add :name, :blank
or +false+ otherwise. +type+ is treated the same as for +add+.
Returns +true+ if an error matches provided +attribute+ and +type+,
def added?(attribute, type = :invalid, options = {}) attribute, type, options = normalize_arguments(attribute, type, **options) if type.is_a? Symbol @errors.any? { |error| error.strict_match?(attribute, type, **options) } else messages_for(attribute).include?(type) end end