40 lines
1.5 KiB
Ruby
40 lines
1.5 KiB
Ruby
class UploadColumnToPaperclip < ActiveRecord::Migration
|
|
include UploadColumnMigration
|
|
|
|
def self.up
|
|
|
|
add_paperclip_fields :products, :setup_file
|
|
Product.reset_column_information
|
|
Product.all.each do |product|
|
|
populate_paperclip_from_upload_column(product, File.join(Rails.root, "public", "files", "downloads"), product[:file], 'setup_file')
|
|
end
|
|
|
|
add_paperclip_fields :product_icons, :icon
|
|
ProductIcon.reset_column_information
|
|
ProductIcon.all.each do |icon|
|
|
ext = icon[:icon].split(".").last
|
|
populate_paperclip_from_upload_column(icon, File.join(Rails.root, "public", "files", "icons"), "#{icon.product.code}_#{icon.size}.#{ext}", 'icon')
|
|
end
|
|
|
|
add_paperclip_fields :screenshots, :image
|
|
Screenshot.reset_column_information
|
|
Screenshot.all.each do |screenshot|
|
|
populate_paperclip_from_upload_column(screenshot, File.join(Rails.root, "public", "files", "images"), screenshot[:image], 'image')
|
|
end
|
|
|
|
add_paperclip_fields :product_images, :image
|
|
ProductImage.reset_column_information
|
|
ProductImage.all.each do |product_image|
|
|
populate_paperclip_from_upload_column(product_image, File.join(Rails.root, "public", "files", "images"), product_image[:image], 'image')
|
|
end
|
|
|
|
end
|
|
|
|
def self.down
|
|
remove_paperclip_fields :products, :setup_file
|
|
remove_paperclip_fields :product_icons, :icon
|
|
remove_paperclip_fields :screenshots, :image
|
|
remove_paperclip_fields :product_images, :image
|
|
end
|
|
end
|