开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜