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

后端 未结 3 1853
隐瞒了意图╮
隐瞒了意图╮ 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:15

    If one wants to delete a file but does not want to specify the full filename you can use the below.

    Can also be used to delete many files or all files in a directory with a specific extension...

    file = Rails.root.join("tmp", "foo*") 
    

    or

    file = Rails.root.join("tmp", ".pdf")  
    

    files = Dir.glob(file) #will build an array of the full filepath & filename(s)
    files.each do |f|
      File.delete(f)
    end
    

提交回复
热议问题