Carrierwave: How to unmount Uploader for batch upload

267 Views Asked by At

I have a Product model which has an :image attribute. It uses carrierwave for image uploading:

mount_uploader :image, ImageUploader

That works fine for my New/Edit form but since I have a batch upload option using roo gem for excel upload, mount_uploader does not allow the image column to populate. I need to disable/unmount the uploader whenever it's an excel batch upload. Below is how my excel upload executes:

def self.import(file)
  spreadsheet = Roo::Spreadsheet.open(file.path)
  header = spreadsheet.row(1)
  (2..spreadsheet.last_row).each do |i|
    row = Hash[[header, spreadsheet.row(i)].transpose]
    product = find_by(id: row["id"]) || new
    product.attributes = row.to_hash
    product.save!
  end
end
0

There are 0 best solutions below