How to remove validation using instance_eval clause in Rails?

后端 未结 18 1885
情话喂你
情话喂你 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:50

    I had a similar problem and was able to get past it using:

    class MyModel << Dummy
      # erase the validations defined in the plugin/gem because they interfere with our own
      Dummy.reset_callbacks(:validate)
      ...
    end
    

    This is under Rails 3.0. The caveat: It does remove ALL validations, so if there are others you want to keep you could try Dummy.skip_callback(...), but I could not figure out the right incantation of arguments to make that work.

提交回复
热议问题