views:

150

answers:

1

Hi,

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

A: 

How about

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

or

validates_attachment_presence :pic1, :if => :is_step5?

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