Created
April 1, 2018 12:50
-
-
Save unixmonkey/6b25b404009ed8754cfef58e5df648ed to your computer and use it in GitHub Desktop.
Remove specific validation from model in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_validator!(validator_class, model_class, field) | |
model_class.class_eval do | |
_validators[field].reject! { |v| v.class == validator_class } | |
cb = _validate_callbacks.detect { |c| c.raw_filter.class == validator_class } | |
_validate_callbacks.delete(cb) if cb | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment