这是在生产应用程序中。我怀疑在文件上传(直接上传到 S3)期间发生了一些事情,并且 blob 没有正确创建。
现在应用程序在某些情况下崩溃,我试图在不删除父记录的情况下删除“幽灵”附件。这可能吗?
irb(main):020:0> s2.presentation_file.attached?
=> true
irb(main):021:0> s2.presentation_file.attachment
=> #<ActiveStorage::Attachment id: 362, name: "presentation_file", record_type: "Speaker", record_id: 219, blob_id: 369, created_at: "2018-05-06 19:44:06">
irb(main):022:0> s2.presentation_file.attachment.blob
=> nil
irb(main):023:0> s2.presentation_file.purge
NoMethodError: undefined method `purge' for nil:NilClass
from (irb):23
最佳答案
我不知道它是怎么发生的,但你可以附上一些图像,只是为了清除它,从而治愈提交:
s2.presentation_file.attach(io: File.open("placeholder.jpg"), filename: 'placeholder.jpg')
s2.presentation_file.purge
关于ruby-on-rails - ActiveStorage : record returns attached? 为真,但 blob 为零。如何删除 "ghost"附件?这怎么发生的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50223308/