instance method read_attribute_for_validation

Ruby on Rails edge

Since v8.1.4

Available in: v8.1.4 edge

Signature

read_attribute_for_validation(attribute)

Hook method defining how an attribute value should be retrieved. By default this is assumed to be an instance named after the attribute. If the attribute does not exist, nil is returned. Override this method in subclasses should you need to retrieve the value for a given attribute differently:

“‘ class MyClass

include ActiveModel::Validations

def initialize(data = {})
  @data = data
end

def read_attribute_for_validation(key)
  @data[key]
end

end “‘

Parameters

attribute req
Source
# File activemodel/lib/active_model/validations.rb, line 491
    def read_attribute_for_validation(attribute)
      send(attribute) if respond_to?(attribute, true)
    end

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

Defined in ActiveModel::Validations

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close