[英]Paperclip with Sidekiq not working
我创建了一个Sidekiq工作程序,该工作程序将复制具有Paperclip附件的现有记录,但似乎无法正常工作。
#controller
product = Product.find(2)
SuperWorker.perform_in(5.minutes, product.id)
#worker
class SuperWorker
include Sidekiq::Worker
def perform(product_id)
product = Product.find(product_id)
product.generate_clone
end
end
#product model
...
has_attached_file :front_image, :styles => { :medium => "415x500>", :thumb => "100x100>" }, :default_url => "/assets/thumbnail-default.jpg"
validates_attachment_content_type :front_image, :content_type => ['image/png']
has_attached_file :back_image, :styles => { :medium => "415x500>", :thumb => "100x100>" }, :default_url => "/assets/thumbnail-default.jpg"
validates_attachment_content_type :back_image, :content_type => ['image/png']
def generate_clone
new_product = self.dup
new_product.front_image = self.front_image
new_product.back_image = self.back_image
new_product.save
end
当我在控制台中复制记录时,似乎可以正常工作,这就是为什么我很困惑为什么它不能在计划任务中工作的原因。 这是我在Rails控制台中做到的方法。
p = Product.find(2)
new_p = p.dup
new_p.front_image = p.front_image
new_p.back_image = p.back_image
new_p.save
这可以正常工作,但在sidekiq worker中则不能。
希望您能阐明我在此操作上做错的任何事情和/或如果我错过了某些事情。
谢谢。
拉尔夫
我通过不使用.dup
函数解决了此问题
p = Product.find(2)
new_p = Product.new
new_p.field1 = p.field1
new_p.field2 = p.field2
...
new_p.front_image = p.front_image
new_p.back_image = p.back_image
new_p.save
工作完美。 我希望这可以帮助任何对此有疑问的人。
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.