undefined method `destroy_block' for ImageUploader::Attacher:Class
ParthivSavani opened this issue · comments
Hello All,
My requirement is I want to move the upload and delete images in the background. So, I'm am using backgrounding
plugin.
I'm running sidekiq worker in the Attacher.promote
block from the ImageUploader model to upload the file and It works fine but when I delete that image from the frontend and submit, then Attacher.destroy
or Attacher.destroy_block
is not calling. See below my code.
Reference - https://shrinerb.com/docs/plugins/backgrounding
class ImageUploader < BaseUploader
plugin :backgrounding
Attacher.validate do
validate_max_size self.class.module_parent::MAX_SIZE
validate_mime_type %w[image/jpeg image/png image/webp image/tiff]
validate_extension %w[jpg jpeg png webp tiff tif]
end
Attacher.promote do
PromoteJob.perform_async(self.class.name, record.class.name, record.id, name, file_data)
end
Attacher.destroy do
DestroyJob.perform_async(self.class.name, data)
end
One more error in the below code - undefined method from_data
class DestroyJob
include Sidekiq::Worker
def perform(attacher_class, data)
attacher_class = Object.const_get(attacher_class)
attacher = attacher_class.from_data(data)
attacher.destroy
end
end
Please help. Thanks
It's very hard to debug this. Reproducing the problem would be very helpful. Here is a branch I have created with things set up for sidekiq testing (it's not ideal, but it is a starting point): https://github.com/BKSpurgeon/debugging-shrine-example/tree/debug-promotion-problem - would you be able to play around with it to see if you can reproduce the problem - or to otherwise reproduce your problem? I'll try and come back to that particular template when I get a clear opportunity.
Also if you are deleting things on the client side why not consider using the remove attachments plugin: https://shrinerb.com/docs/plugins/remove_attachment
@ParthivSavani I think you might be using an older version of Shrine, as you seem to be mixing 2.x and 3.x backgrounding APIs. In Shrine 3.x Attacher.destroy_block
is definitely defined by the background
, and Attacher.from_data
is part of the core Shrine API.