This is in a production app. I suspect something happened during a file upload (direct uploads to S3) and the blob did not get created properly.
Now the app crashes in some cases and I am trying to remove the "ghost" attachment without deleting the parent record. Is this possible?
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
I've no idea how it happened, but you can attach some image, just in order to purge it, thus healing the submission:
s2.presentation_file.attach(io: File.open("placeholder.jpg"), filename: 'placeholder.jpg')
s2.presentation_file.purge
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With