-
-
Save ukazap/de4c0dd5e8cefa812950f807a2600144 to your computer and use it in GitHub Desktop.
Removing validation of a model declared on a gem
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
# 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 |
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
# 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