Rails 4: 试图破坏图片时堆栈级别太深
Rails 4: stack level too deep when trying to destroy picture
您好,我在我的应用程序中正常设置了 Paperclip 和 S3 用于上传图片,这是我用于附件的模型:
class Picture < ActiveRecord::Base
belongs_to :ofert, dependent: :destroy
has_attached_file :image, :styles => { :medium => "300x300#", :thumb => "100x100>", :large => "600x400#", :morethumb => "50x50#", :ultrathumb => "25x25#" },
:default_url => "https://s3-sa-east-1.amazonaws.com/:s3_bucket/ofert_defaults/:style/brown_hat.jpg"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates_attachment_presence :image, :if => :isProduction?
validates_attachment_size :image, :less_than => 5.megabytes
#process_in_background :image, processing_image_url: 'https://s3-sa-east-1.amazonaws.com/:s3_bucket/ofert_defaults/:style/brown_hat.jpg'
end
上面的方法非常有效,但是,当我尝试销毁图片时:
picture.destroy
我收到以下错误:stack level too deep
但如果我改为执行以下操作:
picture.delete
它有效,但是上面只删除了记录而不是上传到我的 S3 存储桶的文件,知道吗?
这是 rails 中的错误。阅读 here
使用
belongs_to :ofert, dependent: :destroy
会导致循环(假设你在关联模型中也有类似的线'Ofert')
您可以尝试在这些模型之一中将其替换为 dependent :delete 或在两者中编写 after_destroy 方法以手动销毁关联模型。
在 Whosebug
上阅读此讨论 here
您好,我在我的应用程序中正常设置了 Paperclip 和 S3 用于上传图片,这是我用于附件的模型:
class Picture < ActiveRecord::Base
belongs_to :ofert, dependent: :destroy
has_attached_file :image, :styles => { :medium => "300x300#", :thumb => "100x100>", :large => "600x400#", :morethumb => "50x50#", :ultrathumb => "25x25#" },
:default_url => "https://s3-sa-east-1.amazonaws.com/:s3_bucket/ofert_defaults/:style/brown_hat.jpg"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates_attachment_presence :image, :if => :isProduction?
validates_attachment_size :image, :less_than => 5.megabytes
#process_in_background :image, processing_image_url: 'https://s3-sa-east-1.amazonaws.com/:s3_bucket/ofert_defaults/:style/brown_hat.jpg'
end
上面的方法非常有效,但是,当我尝试销毁图片时:
picture.destroy
我收到以下错误:stack level too deep
但如果我改为执行以下操作:
picture.delete
它有效,但是上面只删除了记录而不是上传到我的 S3 存储桶的文件,知道吗?
这是 rails 中的错误。阅读 here
使用
belongs_to :ofert, dependent: :destroy
会导致循环(假设你在关联模型中也有类似的线'Ofert') 您可以尝试在这些模型之一中将其替换为 dependent :delete 或在两者中编写 after_destroy 方法以手动销毁关联模型。 在 Whosebug
上阅读此讨论 here