method
validation_context
v7.2.3 -
Show latest stable
- Class:
ActiveModel::Validations
validation_contextpublic
Returns the context when running validations.
This is useful when running validations except a certain context (opposite to the on option).
class Person include ActiveModel::Validations attr_accessor :name validates :name, presence: true, if: -> { validation_context != :custom } end person = Person.new person.valid? #=> false person.valid?(:new) #=> false person.valid?(:custom) #=> true