Conditional Validation with Paperclip difficult

a 夏天 提交于 2020-01-16 08:48:13

问题


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?

Thanks, Michael


回答1:


How about

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

or

validates_attachment_presence :pic1, :if => :is_step5?

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


来源:https://stackoverflow.com/questions/2595164/conditional-validation-with-paperclip-difficult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!