How to remove validation using instance_eval clause in Rails?

后端 未结 18 1881
情话喂你
情话喂你 2021-02-01 02:11

I would like to enhance existing class using instance_eval. There original definition contains validation, which require presence of certain fields, ie:

class Du         


        
18条回答
  •  星月不相逢
    2021-02-01 02:55

    In Rails 4.1,

    I was able to do _validate_callbacks.clear. In my case, I wanted all the validations for a gem removed, so I could create my own. I did this in a module that was patched into the class.

    Module #Name
       extend ActiveSupport::Concern
       included do
            _validate_callbacks.clear
            #add your own validations now
       end
    end
    

提交回复
热议问题