I have a very specific situation where I want to force an instance of a model not valid.
Something like this:
user = User.new
user.valid? #true
user.make_not_valid!
user.valid? #false
Any way to achieve that?
Thanks!
You can do:
validate :forced_to_be_invalid
def make_not_valid!
@not_valid = true
end
private
def forced_to_be_invalid
errors.add(:base, 'has been forced to be invalid') if @not_valid
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With