method
validation_context
v8.0.0 -
Show latest stable
- Class:
ActiveModel::Validations::ClassMethods
validation_context()public
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