跳过载波整合和处理验证 [英] skip carrierwave Integirty and Processing validation

查看:121
本文介绍了跳过载波整合和处理验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我列出了carrierwave上传类中的一些扩展名。

  def extension_white_list 
%w(doc docx)
end

在某些情况下,我想跳过完整性验证,同时保存记录。但由于默认情况下它们的文档validates_integrity_of验证存在。



https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Validate-uploads-with-Active-Record



任何人都可以告诉我如何跳过这种验证吗?

解决方案

in uploaders / file_uploader.rb

  def extension_white_list 
model.do_i_need_validation?
%w(doc docx)
else
%w(pdf)
结束
结束

并在模型中定义此实例方法

  def do_i_need_validation? 
条件? ? true:false
end

只需将适合您的应用程序的内容替换为


I have white listed some of the extensions in the carrierwave uploader class

def extension_white_list
    %w(doc docx)
end

In some cases I would like to skip the Integrity validation while saving a record. But as per their documentation validates_integrity_of validation exist by default.

https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Validate-uploads-with-Active-Record

can anyone please tell me how to skip such validation ?

解决方案

in uploaders/file_uploader.rb

def extension_white_list
  model.do_i_need_validation?
    %w(doc docx)
  else
    %w(pdf)
  end
end

and define this instance method in the model

def do_i_need_validation?
  condition? ? true : false
end

Just replace the content of the method suitable to your app

这篇关于跳过载波整合和处理验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆