简体   繁体   English

如何禁用所有活动记录验证?

[英]How to disable all active record validations?

I need to disable active record validations on all existing models, is there an easy way to accomplish this? 我需要在所有现有模型上禁用活动记录验证,是否有简单的方法来完成此操作?

EDIT: Since I am warned not to do it here is the reason: its in my pet project, someone else added validations and seed stoped to work. 编辑:由于我被警告不要在这里这样做,原因是:它在我的宠物项目中,其他人添加了验证,种子停止工作。 Due limited time every evening, I wanted to code, not to focus on editing quite complex seed. 由于每天晚上时间有限,我想编写代码,而不是专注于编辑非常复杂的种子。

我不知道一种全局禁用验证的方法,但是在每个实例的基础上,您可以在调用save通过说model.save(validate: false)来禁用验证。

This code will do the job: 此代码将完成此工作:

module ActiveModel
  module Validations
    def valid?(*)
      true
    end
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM