Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save insane-dreamer/513307 to your computer and use it in GitHub Desktop.
Save insane-dreamer/513307 to your computer and use it in GitHub Desktop.
rake to delete attachments created with tests
namespace :paperclip do
desc 'deletes stale attachments (i.e., created by tests)'
task :stale => :environment do
Dir.chdir('public/system/items')
dirs = Dir.glob("[^\.]*")
items = Asset.all.collect(&:id)
count = 0
dirs.each { |d|
unless items.include?(d.to_i)
print '.'
system("rm -rf #{d}")
count += 1
end
}
puts "#{count} folders deleted (for which no item found in database)."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment