Based on http://fernandomarcelo.com/2012/05/paperclip-how-to-move-existing-attachments-to-a-new-path/
For simplicity, I wanted to update my current attachments to a new directory.
My old model, VideoAttachment, had the following options:
class VideoAttachment < ActiveRecord::Base
has_attached_file :video,
path: ':rails_root/uploads/:class/:id/:style/:filename',
url: '/images/:class/:style/:token',
styles: {
thumb: {
format: 'jpg'
}
}
end
My new version looks like this:
class VideoAttachment < ActiveRecord::Base
has_attached_file :video,
styles: {
thumb: {
format: 'jpg'
},
webm: {
format: 'webm'
}
},
url: '/system/:class/:attachment/:id_partition/:style/:token.:extension',
end
VideoAttachment.all.each do |video_attachment|
old_options = {
path: ':rails_root/uploads/:class/:id/:style/:filename',
styles: {
thumb: {
format: 'jpg'
}
}
}
old_path = Paperclip::Attachment.new(:video, video_attachment, old_options).path
file = File.new(old_path)
video_attachment.video = file
video_attachment.save
file.close
end
Since I added a new style, I wanted to do a reprocess (which is done automatically by paperclip when you update the attachment).