Rails Dragonfly find files in use

别来无恙 提交于 2019-12-12 06:04:42

问题


We are using Dragonfly for file and image upload in the app and in the Rails Admin.

Dragonfly in app part Users can apply for jobs and add their resume as attachment. When user uploads attachments and sucesfully apply for a job the files get deleted.

Dragonfly in Rails Admin part Admins can create pages with attachments and images in the Rails Admin part, these attachments are linked via the specific tables.

Problem When a user is applying for a job but doesn't finish the apply the files remain unused on the server. Now dragonfly stores the files from the Admin on the same place as the user uploaded files.

Question Is it possible to filter out the files that are not linked in the DB and bulk delete these files?


回答1:


I've fixed this simply by supplying a path when storing the data:

path = "ApplyAttachments/" + Time.now.strftime("%d%m%Y_%H%M") + "_" + rand(1000).to_s + "_" + data.original_filename.to_s
file["file"] = Dragonfly[:images].store(data, :path => path)


来源:https://stackoverflow.com/questions/28288299/rails-dragonfly-find-files-in-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!