使用 Paperclip 进行条件验证困难 [英] Conditional Validation with Paperclip difficult
本文介绍了使用 Paperclip 进行条件验证困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目",它经历了一个多页的创建过程.图像在第五步上传,我使用属性完成"跟踪这些步骤.在验证图像是否附有回形针时,我在使用以下代码时遇到问题:
I have an "item", which goes through a multi-page creation process. Images are uploaded at step five, and I keep track of the steps by using the attribute "complete". When validating whether an image is attached with paperclip, I get problems using the code below:
validates_attachment_presence :pic1, :if => Proc.new { |u| u.complete == "step5"}
似乎我无法访问完整"属性,因为活动记录对象似乎是回形针图像.有没有办法让我检查我在流程中的哪个点并有条件地验证?
It seems that I can't access the "complete" attribute, as the active-record object seems to be the paperclip image. Is there a way for me to check at which point in the process I am and validate conditionally?
谢谢,迈克尔
推荐答案
怎么样
validates_attachment_presence :pic1, :if => 'complete == "setp5"?'
或
validates_attachment_presence :pic1, :if => :is_step5?
def is_step5?
self.complete == "step5"
end
这篇关于使用 Paperclip 进行条件验证困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文