carrierwave-base64 icon indicating copy to clipboard operation
carrierwave-base64 copied to clipboard

NoMethodError undefined method _will_change

Open donatoaz opened this issue 6 years ago • 1 comments

Hi y'all. I am not sure if this is an issue with carrierwave-base64 itself or with carrierwave itself.

I am using

root@377275e66746:/app# cat Gemfile.lock | grep carrier
    carrierwave (1.2.3)
    carrierwave-base64 (2.3.2)
      carrierwave (>= 0.8.0)

On the console I do:

myobject.update(before_image: "data:image/png;base64,......long string....")

The error I am getting is:

NoMethodError (undefined method `before_image_will_change!' for #<Servicing:0x007fb21cbb5f50>)

I read this issue on the carrierwave repo, which is from 2011, so I thought I was ok...

This is how I am defining my attribute

  mount_base64_uploader :before_image, PersistentImageUploader, mount_on: :before_image_filename

My PersistentImageUploader is

class PersistentImageUploader < ImageUploader
  configure do |config|
    config.remove_previously_stored_files_after_update = false
  end
end

And ImageUploader

class ImageUploader < BaseUploader
  process format: "jpg"
  process quality: 80
  process interlace: "plane"
  process resize_to_limit: [2000, 2000]

  def extension_white_list
    %w(jpg jpeg png)
  end
end

And BaseUploader

class BaseUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def filename
    return unless original_filename
    extension = MIME::Types[file.content_type].first.extensions.first

    "#{Digest::SHA1.hexdigest(file.read)}.#{extension}"
  end

  def interlace(type)
    manipulate! do |img|
      img.interlace(type.to_s)
      img = yield(img) if block_given?
      img
    end
  end

  def quality(percentage)
    manipulate! do |img|
      img.quality(percentage.to_s)
      img = yield(img) if block_given?
      img
    end
  end
end

donatoaz avatar Dec 05 '18 11:12 donatoaz

thank you for reporting! Can you rename your attribute to something different to before_image, and check if it works?

y9v avatar Dec 10 '18 08:12 y9v