开发者

Conditional Validation with Paperclip difficult

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 "complet开发者_运维知识库e" 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?

Thanks, Michael


How about

validates_attachment_presence :pic1, :if => 'complete == "setp5"?'

or

validates_attachment_presence :pic1, :if => :is_step5?

def is_step5?
  self.complete == "step5"
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜