rmagick卡在一个无限循环中,一遍又一遍地创建一个图像

时间:2013-05-24 20:28:18

标签: 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(*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

知道为什么会这样,或者如何调试它?

1 个答案:

答案 0 :(得分:2)

您的问题不在rmagick,而是由于

after_save :process

然后在process

save!

创建无限递归。

相关问题