instance method where

Ruby on Rails 7.2.3

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

where(attribute, type = nil, **options)

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

Parameters

attribute req
type opt = nil
options keyrest
Source
# 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

Defined in activemodel/lib/active_model/errors.rb line 189 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveModel::Errors

Type at least 2 characters to search.

↑↓ navigate · open · esc close