无法删除载波中 collection 的最后一个图像文件

Cannot remove the last image file of a collection in carrierwave

我想有选择地删除上传的图片作为 issue#1704 提供的解决方案。 一切正常,除了当我想删除 collection 中的最后一张图像时它不会将 images 值分配给 [] 下面是我手动测试程序的调试模式和故意将 images 分配给 [] 但模型坚持保持其先前的值!!

我想你必须在新标签页中打开下面的图片并放大才能看到细节:D

代码如下:

数据库模式:

create_table "furniture_types", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
  t.string   "name"
  t.text     "comment",         limit: 65535
  t.datetime "created_at",                                    null: false
  t.datetime "updated_at",                                    null: false
  t.json     "images"
  t.boolean  "is_inside_type",                default: false
  t.boolean  "is_outside_type",               default: false
end

如何解决这个问题?

正如我在 the issue 中提到的,我已经打开,CarrierWave 故意拒绝上传者列的空值或 nil 值,因此我想出了一个绕过限制的技巧,而且效果很好!

@instance.write_attribute(:images, nil)