无法销毁Blob滑轨

时间:2019-03-06 02:23:08

标签: ruby-on-rails ruby ruby-on-rails-5

我无法通过以下代码销毁附件图像:

@image = ActiveStorage::Blob.find(params[:id])
@image.purge

但是,如果这样做,我可以删除附件图像:

@image = ActiveStorage::Attachment.find(params[:id])
@image.purge

我的模型如下:

class Device < ApplicationRecord
    has_many_attached :images
end

当我尝试通过实例化Blob删除图像时,在清除时会看到以下回滚,但是打印@image.errors.to_json只会显示一个空哈希。但是,我可以打印图像的id和其他属性,因此我很肯定自己正在寻找并尝试删除正确的图像。

这是我的控制台输出,用于删除Blob

ActiveStorage::Blob Load (0.2ms)  SELECT  "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 23], ["LIMIT", 1]]
↳ app/controllers/rooms_controller.rb:68
(0.1ms)  begin transaction
↳ app/controllers/rooms_controller.rb:69
ActiveStorage::Attachment Exists (0.3ms)  SELECT  1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ?  [["blob_id", 23], ["LIMIT", 1]]
↳ app/controllers/rooms_controller.rb:69
(0.1ms)  rollback transaction
↳ app/controllers/rooms_controller.rb:69 

0 个答案:

没有答案