method

validation_context

rails latest stable - Class: ActiveModel::Validations::ClassMethods

Method not available on this version

This method is only available on newer versions. The first available version (v8.0.0) is shown here.

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