Method: ActiveModel::Errors#where

Defined in:
activemodel/lib/active_model/errors.rb

#where(attribute, type = nil, **options) ⇒ Object

Search for errors matching attribute, type, or options.

Only supplied params will be matched.

person.errors.where(:name) # => all name errors.
person.errors.where(:name, :too_short) # => all name errors being too short
person.errors.where(:name, :too_short, minimum: 2) # => all name errors being too short and minimum is 2


189
190
191
192
193
194
# File 'activemodel/lib/active_model/errors.rb', line 189

def where(attribute, type = nil, **options)
  attribute, type, options = normalize_arguments(attribute, type, **options)
  @errors.select { |error|
    error.match?(attribute, type, **options)
  }
end