Victor Lam
Victor Lam

Reputation: 3710

How to remove a specific file in Rails public folder?

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?

Upvotes: 2

Views: 11751

Answers (2)

mylescarrick
mylescarrick

Reputation: 1680

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...

Upvotes: 7

John Topley
John Topley

Reputation: 115372

Ruby's File class has a delete method:

File.delete(Rails.root + '/foo.jpg')

Upvotes: 36

Related Questions