开发者

How to remove a specific file in Rails public folder?

开发者 https://www.devze.com 2023-01-04 06:39 出处:网络
User in my web app are able to upload file. I use Paperclip to handle file attachment issue. Is there an开发者_开发问答y method if I would like to remove any specific user-uploaded file programmatical

User in my web app are able to upload file. I use Paperclip to handle file attachment issue. Is there an开发者_开发问答y method if I would like to remove any specific user-uploaded file programmatically?


Ruby's File class has a delete method:

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号