【发布时间】:2021-03-05 04:23:52
【问题描述】:
伙计们,清除图片附件真是太难了!一切“似乎”都在工作,但图像在删除后继续显示。
查看
<%= link_to 'delete', delete_image_attachment_job_entry_url(entry, entry.images[image].signed_id), method: :delete, data: { confirm: 'Are you sure?' } %>
控制器
@asset = ActiveStorage::Attachment.find_by(id: params[:id])
@asset&.purge
当它运行时,控制台显示如下:
ActiveStorage::Attachment Load (0.2ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ? LIMIT ? [["id", 8], ["LIMIT", 1]]
↳ app/controllers/job_entries_controller.rb:59:in `delete_image_attachment'
ActiveStorage::Attachment Destroy (14.7ms) DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ? [["id", 8]]
↳ app/controllers/job_entries_controller.rb:61:in `delete_image_attachment'
ActiveStorage::Blob Load (0.2ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
↳ app/controllers/job_entries_controller.rb:61:in `delete_image_attachment'
(0.1ms) begin transaction
↳ app/controllers/job_entries_controller.rb:61:in `delete_image_attachment'
ActiveStorage::Attachment Exists? (0.1ms) SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ? [["blob_id", 100], ["LIMIT", 1]]
↳ app/controllers/job_entries_controller.rb:61:in `delete_image_attachment'
ActiveStorage::Attachment Load (0.1ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = ? AND "active_storage_attachments"."record_type" = ? AND "active_storage_attachments"."name" = ? LIMIT ? [["record_id", 100], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
↳ app/controllers/job_entries_controller.rb:61:in `delete_image_attachment'
ActiveStorage::Blob Destroy (3.7ms) DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? [["id", 100]]
↳ app/controllers/job_entries_controller.rb:61:in `delete_image_attachment'
(7.9ms) commit transaction
↳ app/controllers/job_entries_controller.rb:61:in `delete_image_attachment'
S3 Storage (234.1ms) Deleted file from key: 4xnzcc3d4ml1lnw2ma40oqsy78mz
S3 Storage (350.2ms) Deleted files by key prefix: variants/4xnzcc3d4ml1lnw2ma40oqsy78mz/
然而,当我刷新图库页面时,图像仍然存在!让我发疯...希望有帮助!
【问题讨论】:
标签: ruby-on-rails rails-activestorage