Skip to content

Instantly share code, notes, and snippets.

namespace :db do
desc "Find orphaned records. Set DELETE=true to delete any discovered orphans."
task :find_orphans => :environment do
found = false
model_base = Rails.root.join('app/models')
Dir[model_base.join('**/*.rb').to_s].each do |filename|
@builtinnya
builtinnya / s3_copy_attachments.rb
Created August 25, 2015 12:24
Paperclip S3 copy attachments
### S3 implementation of Paperclip module that supports deep
### cloning of objects by copying image attachments.
###
### Tested with: aws-sdk (1.33.0)
###
### Refer to Paperclip issue: https://github.com/thoughtbot/paperclip/issues/1361#issuecomment-39684643
### Original gist works with fog: https://gist.github.com/stereoscott/10011887
### gist works from which this code is derived: https://gist.github.com/ksin/7747334d60b1947f14e9
module Paperclip
@airblade
airblade / copy_attachments.rb
Created November 10, 2015 11:01
Copies S3-stored Paperclip attachments from one AR model to another
# lib/paperclip/copy_attachments.rb
# Copies S3-stored Paperclip attachments from one AR model to another.
#
# This module should be mixed into the target AR model.
if Gem::Version.new(::AWS::VERSION) >= Gem::Version.new(2)
raise NotImplementedError, 'coded for aws-sdk v1'
end