Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save unixmonkey/6b25b404009ed8754cfef58e5df648ed to your computer and use it in GitHub Desktop.
Save unixmonkey/6b25b404009ed8754cfef58e5df648ed to your computer and use it in GitHub Desktop.
Remove specific validation from model in Rails
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