Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@luizpicolo
Forked from brenes/model_extension.rb
Created January 4, 2017 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizpicolo/28d7b9f14c97f8db287a721948f457bc to your computer and use it in GitHub Desktop.
Save luizpicolo/28d7b9f14c97f8db287a721948f457bc 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment