0

I'm using rmagick to create a montage. After I submit a request, it gets stuck in an infinite loop, and the request continues to create the same image over, and over, until I manually restart server:

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

Any idea why this is happening, or how to debug it?

4

1 回答 1

2

Your problem is not in rmagick, but due to

after_save :process

then inside process

save!

which creates an infinite recursion.

于 2013-05-24T20:32:03.387 回答