我正在尝试销毁属于父记录的记录。但是 Rails 不会因为stack level too deep
错误而让我这样做。
我的类(简化)是这样构建的:
class Album < ActiveRecord::Base
has_many :photos, dependent: :destroy
accepts_nested_attributes_for :photos, reject_if: lambda { |p| p[:image].blank? }
...
end
class Photo < ActiveRecord::Base
belongs_to :album
mount_uploader :image, PhotoUploader
end
当我尝试以下操作时,出现异常:
Photo.destroy(12) # where 12 is the ID of the photo I want to destroy
# note that Photo.delete(12) works fine, but doesn't remove the image from the file system
我不明白为什么销毁照片会触发此错误。也许它carrierwave
与它的mount_uploader
?
编辑 1:这肯定与carrierwave
. 在我的上传器中,我有以下代码被多次调用(直到堆栈太深):
def unprocessed_image_filename
match_data = /^original_(.+)_\d{14}\.\D{3,4}$/.match(File.basename(model.image.to_s))
match_data ? match_data[1] : "photo"
end
这用于确定各种版本的名称。