How to make carrierwave delete the file when destroying a record?

后端 未结 3 1848
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 02:16

I\'m using the carrierwave gem to upload files.

I have built a system for users to flag images as inappropriate and for admins to remove the images. From what I can

3条回答
  •  一生所求
    2020-12-15 03:18

    Like @mu_is_too_short said, you can use File#delete.

    Here's a code snippet you could use as a helper with a little tweaking in your rails app.

    def remove_file(file)
      File.delete(file)
    end
    

    or if you just have the filename stored in file

    def remove_file(file)
      File.delete("./path/to/#{file}")
    end
    

提交回复
热议问题