Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def old_path
- ':rails_root/public/system/:class/:attachment/:id_partition/:style/:filename'
- end
- def migrate_old_pdf
- logger = Logger.new('./migrate.log')
- Invoice.find_each do |invoice|
- unless invoice.pdf?
- logger.warn "#{invoice.id} にPDFを持っていないためskipします"
- next
- end
- pdf_path = Paperclip::Interpolations.interpolate(old_path, invoice.pdf, 'original')
- unless File.exists?(pdf_path)
- logger.warn "#{invoice.id} にPDFを持っていますがFSにファイルが存在していないのでskipします"
- next
- end
- File.open(pdf_path) do |file|
- invoice.pdf = file
- invoice.save!
- end
- logger.info "#{invoice.id} のPDFを移行しました"
- end
- end
- def delete_old_pdf
- require 'FileUtils'
- Invoice.find_each do |invoice|
- pdf_path = Paperclip::Interpolations.interpolate(old_path, invoice.pdf, 'original')
- FileUtils.rm(pdf_path)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement