Skip to content

Instantly share code, notes, and snippets.

@brenes
Last active February 14, 2024 11:39
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save brenes/4503386 to your computer and use it in GitHub Desktop.
Save brenes/4503386 to your computer and use it in GitHub Desktop.
Removing validation of a model declared on a gem
# We have to remove validations on email, as it's no longer needed.
# Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
Model.class_eval do
_validators.reject!{ |key, _| key == :field }
_validate_callbacks.each do |callback|
callback.raw_filter.attributes.delete :field
end
_validate_callbacks.reject! do |callback|
callback.raw_filter.attributes.empty? || callback.raw_filter.attributes == [:field]
end
end
# We have to remove validations on email, as it's no longer needed.
# Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
Model.class_eval do
_validators.delete(:template)
_validate_callbacks.each do |callback|
if callback.raw_filter.respond_to? :attributes
callback.raw_filter.attributes.delete :template
end
end
end
@pedrosfdcarneiro
Copy link

Very useful. Thanks! 🍻

@Bulatkin
Copy link

Thanks, exactly what I needed.

@rankitranjan
Copy link

awesome 😎

@laurajaime
Copy link

WOW! thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment