I'm using paperclip to upload files to my server, that's working, but I'd like to add validation. I've used seen the railscast episode and Ryan mentioned that there is a way to validate the presence of a an attachment, but that isn't working. When I hit submit, the script inserts empty values in my database.
Is there a way to validate the presence of the attachment?
I've seen this behavior, although I don't entirely understand why paperclip works this way. If you create a model with an attachment, but provide no value for that attachment, then the validation will pass. However, if you create a model with an attachment and set the attachment to nil, the validation will fail. For example:
Model.new.valid? #=> true Model.new(:photo => nil).valid? #=> false
I believe this may have to do with the way paperclip creates a default URL for missing assets (something like /publc/assets/original/missing.png), although it definitely seems like a bug to me. I haven't used paperclip in a while, so I have immediately idea how to get around this other than writing a custom validation that digs around in the paperclip Attachment object.