method
clear_validators!
v5.2.3 -
Show latest stable
-
0 notes -
Class: ActiveModel::Validations::ClassMethods
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2 (0)
- 4.1.8 (38)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
clear_validators!()
public
Clears all of the validators and validations.
Note that this will clear anything that is being used to validate the model for both the validates_with and validate methods. It clears the validators that are created with an invocation of validates_with and the callbacks that are set by an invocation of validate.
class Person include ActiveModel::Validations validates_with MyValidator validates_with OtherValidator, on: :create validates_with StrictValidator, strict: true validate :cannot_be_robot def cannot_be_robot errors.add(:base, 'A person cannot be a robot') if person_is_robot end end Person.validators # => [ # #<MyValidator:0x007fbff403e808 @options={}>, # #<OtherValidator:0x007fbff403d930 @options={on: :create}>, # #<StrictValidator:0x007fbff3204a30 @options={strict:true}> # ]
If one runs Person.clear_validators! and then checks to see what validators this class has, you would obtain:
Person.validators # => []
Also, the callback set by validate :cannot_be_robot will be erased so that:
Person._validate_callbacks.empty? # => true