How to remove validation using instance_eval clause in Rails?

后端 未结 18 1831
情话喂你
情话喂你 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 03:01

    This does not directly answer the question but here's an option you should consider in such a situation: instead of disabling validation, you could set the required fields in a before_validation hook.

    Since you don't need those required fields, set them with some dummy data that satisfies the validation and forget about them.

    No ugly monkey patching.

提交回复
热议问题