Ruby on rails rmagick陷入了一个无限循环,一次又一次地创建图像
我正在使用Ruby on rails rmagick陷入了一个无限循环,一次又一次地创建图像,ruby-on-rails,ruby,rmagick,Ruby On Rails,Ruby,Rmagick,我正在使用rmagick创建蒙太奇。在我提交请求后,它会陷入无限循环,请求会一次又一次地继续创建相同的映像,直到我手动重新启动服务器: class LineItem < ActiveRecord::Base has_many :images, as: :imageable, dependent: :destroy after_save :process private def process image_list = Magick::ImageList.new(
rmagick
创建蒙太奇。在我提交请求后,它会陷入无限循环,请求会一次又一次地继续创建相同的映像,直到我手动重新启动服务器:
class LineItem < ActiveRecord::Base
has_many :images, as: :imageable, dependent: :destroy
after_save :process
private
def process
image_list = Magick::ImageList.new(*self.photos.split(','))
montage = image_list.montage do
self.geometry = "182x182+6+6"
self.tile = "4x3"
end
name = "#{self.id}_#{Time.now}.jpg"
montage.write(name)
images.build(source: File.open(name))
save!
end
class LineItem
知道为什么会发生这种情况,或者如何调试它吗 您的问题不在rmagick中,而是由于
after_save :process
然后在过程中
save!
这将创建一个无限递归。啊,当然!嗯。。。除了跳过保存中的回调之外,还有其他选项吗?可能在保存之前使用
:处理,然后不需要使用保存
在方法中,我实际上计划将其移动到后台进程中,但我希望在做任何其他事情之前先确保它工作正常。