User in my web app are able to upload file. I use Paperclip to handle file attachment issue. Is there any method if I would like to remove any specific user-uploaded file programmatically?
+1
A:
Ruby's File
class has a delete
method:
File.delete(Rails.root + '/foo.jpg')
John Topley
2010-06-17 09:59:48
Thanks buddy. :)
siulamvictor
2010-06-17 10:07:33
+2
A:
Deleting it should be as simple as setting it to nil
# assuming...
has_attached_file :picture
@thing.picture = nil
@thing.save
or
@thing.update_attribute(:picture, nil)
and Paperclip will take care of it for you...
mylescarrick
2010-06-17 10:00:06
Thanks. I overlooked in Paperclip Readme and couldn't figure it out before. >.<
siulamvictor
2010-06-17 10:09:05
I like to define a delete_thing= method that looks for typical boolean form return values and deletes the photo if what's passed in is true.def delete_thing=(val) thing = nil if val =~ /true/on/1/; end
Jared
2010-06-17 14:11:39