Search code examples
ruby-on-railsrails-activestorageruby-on-rails-7

The images miss after I update a post


I create a scaffold and trying to upload image with Active_Storage and AWS S3, it's successful for uploading images. However, the images are gone after I enter the "edit" page and click "update" and the terminal told that all the images were deleted, anyone knows how to fix it? edit page and after clicking update This is the model and controller

class Product < ApplicationRecord
  has_many_attached :pictures

  def picture_as_thumbnail(pic)
    return unless pic.content_type.in?(%W[image/jpeg image/png])
    pic.variant(resize_to_limit: [200, 200]).processed
  end
end
def update
    respond_to do |format|
      if @product.update(product_params)
        format.html { redirect_to product_url(@product), notice: 'Product was successfully updated.' }
        format.json { render :show, status: :ok, location: @product }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: @product.errors, status: :unprocessable_entity }
      end
    end
  end

This is terminal after ia click update

12:29:53 web.1  | Started PATCH "/products/9" for 127.0.0.1 at 2023-06-19 12:29:53 +0800
12:29:53 web.1  | Processing by ProductsController#update as TURBO_STREAM
12:29:53 web.1  |   Parameters: {"authenticity_token"=>"[FILTERED]", "product"=>{"name"=>" 123", "description"=>"123", "pictures"=>[""]}, "commit"=>"Update Product", "id"=>"9"}
12:29:53 web.1  |   Product Load (0.1ms)  SELECT "products".* FROM "products" WHERE "products"."id" = ? LIMIT ?  [["id", 9], ["LIMIT", 1]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:65:in `set_product'
12:29:53 web.1  |   TRANSACTION (0.1ms)  begin transaction
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   Product Update (0.3ms)  UPDATE "products" SET "name" = ?, "updated_at" = ? WHERE "products"."id" = ?  [["name", " 123"], ["updated_at", "2023-06-19 04:29:53.491920"], ["id", 9]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   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" = ?  [["record_id", 9], ["record_type", "Product"], ["name", "pictures"]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   ActiveStorage::Attachment Destroy (0.2ms)  DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ?  [["id", 114]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   ActiveStorage::Attachment Destroy (0.1ms)  DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ?  [["id", 115]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   ActiveStorage::Attachment Destroy (0.1ms)  DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ?  [["id", 116]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   Product Update (0.1ms)  UPDATE "products" SET "updated_at" = ? WHERE "products"."id" = ?  [["updated_at", "2023-06-19 04:29:53.501292"], ["id", 9]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   TRANSACTION (12.4ms)  commit transaction
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  |   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 114], ["LIMIT", 1]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  | [ActiveJob] Enqueued ActiveStorage::PurgeJob (Job ID: 6bb95756-b75d-4e6f-b24f-3ed1b17b2721) to Async(default) with arguments: #<GlobalID:0x00007f2844044278 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/114>>
12:29:53 web.1  |   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 115], ["LIMIT", 1]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  | [ActiveJob] Enqueued ActiveStorage::PurgeJob (Job ID: be9b3033-8e3b-43ae-8c61-fe05889b6e6b) to Async(default) with arguments: #<GlobalID:0x00007f2844069ac8 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/115>>
12:29:53 web.1  |   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 116], ["LIMIT", 1]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:41:in `block in update'
12:29:53 web.1  | [ActiveJob] Enqueued ActiveStorage::PurgeJob (Job ID: 24396ba7-0367-457d-a9d6-a0320da253bb) to Async(default) with arguments: #<GlobalID:0x00007f283c25e110 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/116>>
12:29:53 web.1  | Redirected to http://127.0.0.1:3000/products/9
12:29:53 web.1  | Completed 302 Found in 35ms (ActiveRecord: 13.7ms | Allocations: 10652)
12:29:53 web.1  |
12:29:53 web.1  |
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 114], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721] Performing ActiveStorage::PurgeJob (Job ID: 6bb95756-b75d-4e6f-b24f-3ed1b17b2721) from Async(default) enqueued at 2023-06-19T04:29:53Z with arguments: #<GlobalID:0x00007f283c274758 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/114>>
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   TRANSACTION (0.1ms)  begin transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::Attachment Exists? (0.1ms)  SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ?  [["blob_id", 114], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::VariantRecord Load (0.0ms)  SELECT "active_storage_variant_records".* FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."blob_id" = ?  [["blob_id", 114]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   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", 42], ["record_type", "ActiveStorage::VariantRecord"], ["name", "image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::Attachment Destroy (0.3ms)  DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ?  [["id", 117]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::VariantRecord Destroy (0.1ms)  DELETE FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."id" = ?  [["id", 42]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::Attachment Load (0.0ms)  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", 114], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::Blob Destroy (0.2ms)  DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ?  [["id", 114]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   TRANSACTION (19.6ms)  commit transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   ActiveStorage::Blob Load (0.8ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 117], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721] Enqueued ActiveStorage::PurgeJob (Job ID: ef5b8011-f98d-484b-88c6-11c6567ef8b1) to Async(default) with arguments: #<GlobalID:0x00007f283c102320 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/117>>
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 115], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b] Performing ActiveStorage::PurgeJob (Job ID: be9b3033-8e3b-43ae-8c61-fe05889b6e6b) from Async(default) enqueued at 2023-06-19T04:29:53Z with arguments: #<GlobalID:0x00007f283c057e48 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/115>>
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   TRANSACTION (0.0ms)  begin transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::Attachment Exists? (0.1ms)  SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ?  [["blob_id", 115], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::VariantRecord Load (0.1ms)  SELECT "active_storage_variant_records".* FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."blob_id" = ?  [["blob_id", 115]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   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", 43], ["record_type", "ActiveStorage::VariantRecord"], ["name", "image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::Attachment Destroy (0.3ms)  DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ?  [["id", 118]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::VariantRecord Destroy (0.1ms)  DELETE FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."id" = ?  [["id", 43]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::Attachment Load (0.0ms)  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", 115], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::Blob Destroy (0.1ms)  DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ?  [["id", 115]]
12:29:53 web.1  | Started GET "/products/9" for 127.0.0.1 at 2023-06-19 12:29:53 +0800
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   TRANSACTION (12.8ms)  commit transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 118], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b] Enqueued ActiveStorage::PurgeJob (Job ID: 398c43df-6c08-4a1a-bdb2-ff2de3c07ef1) to Async(default) with arguments: #<GlobalID:0x00007f27d7832970 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/118>>
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 116], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb] Performing ActiveStorage::PurgeJob (Job ID: 24396ba7-0367-457d-a9d6-a0320da253bb) from Async(default) enqueued at 2023-06-19T04:29:53Z with arguments: #<GlobalID:0x00007f27d7855268 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/116>>
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   TRANSACTION (0.0ms)  begin transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   ActiveStorage::Attachment Exists? (0.1ms)  SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ?  [["blob_id", 116], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   ActiveStorage::VariantRecord Load (0.1ms)  SELECT "active_storage_variant_records".* FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."blob_id" = ?  [["blob_id", 116]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   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", 44], ["record_type", "ActiveStorage::VariantRecord"], ["name", "image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   ActiveStorage::Attachment Destroy (0.3ms)  DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = ?  [["id", 119]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   ActiveStorage::VariantRecord Destroy (0.1ms)  DELETE FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."id" = ?  [["id", 44]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   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", 116], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   ActiveStorage::Blob Destroy (0.2ms)  DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ?  [["id", 116]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   TRANSACTION (13.8ms)  commit transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   ActiveStorage::Blob Load (0.2ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 119], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb] Enqueued ActiveStorage::PurgeJob (Job ID: c7ce24e2-bbbc-4134-a932-07d61b1aa352) to Async(default) with arguments: #<GlobalID:0x00007f2844904fc0 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/119>>
12:29:53 web.1  | Processing by ProductsController#show as TURBO_STREAM
12:29:53 web.1  |   Parameters: {"id"=>"9"}
12:29:53 web.1  |   Product Load (0.1ms)  SELECT "products".* FROM "products" WHERE "products"."id" = ? LIMIT ?  [["id", 9], ["LIMIT", 1]]
12:29:53 web.1  |   ↳ app/controllers/products_controller.rb:65:in `set_product'
12:29:53 web.1  |   Rendering layout layouts/application.html.erb
12:29:53 web.1  |   Rendering products/show.html.erb within layouts/application
12:29:53 web.1  |   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" = ?  [["record_id", 9], ["record_type", "Product"], ["name", "pictures"]]
12:29:53 web.1  |   ↳ app/views/products/_product.html.erb:12
12:29:53 web.1  |   Rendered products/_product.html.erb (Duration: 3.0ms | Allocations: 1068)
12:29:53 web.1  |   Rendered products/show.html.erb within layouts/application (Duration: 4.9ms | Allocations: 1686)
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 117], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1] Performing ActiveStorage::PurgeJob (Job ID: ef5b8011-f98d-484b-88c6-11c6567ef8b1) from Async(default) enqueued at 2023-06-19T04:29:53Z with arguments: #<GlobalID:0x00007f28459c38c0 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/117>>
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   TRANSACTION (0.1ms)  begin transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   ActiveStorage::Attachment Exists? (0.2ms)  SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ?  [["blob_id", 117], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   ActiveStorage::VariantRecord Load (0.1ms)  SELECT "active_storage_variant_records".* FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."blob_id" = ?  [["blob_id", 117]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   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", 117], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   ActiveStorage::Blob Destroy (0.2ms)  DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ?  [["id", 117]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   TRANSACTION (13.4ms)  commit transaction
12:29:53 web.1  |   Rendered /home/cc/.rvm/gems/ruby-3.2.1/gems/hotwire-livereload-1.2.3/app/views/hotwire/livereload/_head_action_cable.html.erb (Duration: 0.6ms | Allocations: 738)
12:29:53 web.1  |   Rendered shared/_nav.html.erb (Duration: 0.1ms | Allocations: 8)
12:29:53 web.1  |   Rendered layout layouts/application.html.erb (Duration: 58.1ms | Allocations: 18951)
12:29:53 web.1  | Completed 200 OK in 67ms (Views: 60.1ms | ActiveRecord: 0.3ms | Allocations: 19894)
12:29:53 web.1  |
12:29:53 web.1  |
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   ActiveStorage::Blob Load (0.1ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 118], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1] Performing ActiveStorage::PurgeJob (Job ID: 398c43df-6c08-4a1a-bdb2-ff2de3c07ef1) from Async(default) enqueued at 2023-06-19T04:29:53Z with arguments: #<GlobalID:0x00007f283c1e30c8 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/118>>
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   TRANSACTION (0.1ms)  begin transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   ActiveStorage::Attachment Exists? (0.1ms)  SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ?  [["blob_id", 118], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   ActiveStorage::VariantRecord Load (0.0ms)  SELECT "active_storage_variant_records".* FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."blob_id" = ?  [["blob_id", 118]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   ActiveStorage::Attachment Load (0.0ms)  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", 118], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   ActiveStorage::Blob Destroy (0.2ms)  DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ?  [["id", 118]]
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   TRANSACTION (14.0ms)  commit transaction
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   S3 Storage (379.9ms) Deleted file from key: ybi88vnlp6prj2j7kxhkbh86da11
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   S3 Storage (359.6ms) Deleted file from key: 4vkiyyuj98xdrayul8li1xjey1ue
12:29:53 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   S3 Storage (308.0ms) Deleted file from key: n0hplu1t8id2olzuo6xfy2cm5xzq
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   S3 Storage (302.4ms) Deleted file from key: nnadu43xtf3k4mqrbe53oa8bj9yy
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721]   S3 Storage (81.4ms) Deleted files by key prefix: variants/ybi88vnlp6prj2j7kxhkbh86da11/
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [6bb95756-b75d-4e6f-b24f-3ed1b17b2721] Performed ActiveStorage::PurgeJob (Job ID: 6bb95756-b75d-4e6f-b24f-3ed1b17b2721) from Async(default) in 505.91ms
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   ActiveStorage::Blob Load (0.3ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 119], ["LIMIT", 1]]
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352] Performing ActiveStorage::PurgeJob (Job ID: c7ce24e2-bbbc-4134-a932-07d61b1aa352) from Async(default) enqueued at 2023-06-19T04:29:53Z with arguments: #<GlobalID:0x00007f27d7839ab8 @uri=#<URI::GID gid://your-cool-app/ActiveStorage::Blob/119>>
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   TRANSACTION (0.1ms)  begin transaction
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   ActiveStorage::Attachment Exists? (0.2ms)  SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = ? LIMIT ?  [["blob_id", 119], ["LIMIT", 1]]
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   ActiveStorage::VariantRecord Load (0.1ms)  SELECT "active_storage_variant_records".* FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."blob_id" = ?  [["blob_id", 119]]
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   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", 119], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   ActiveStorage::Blob Destroy (0.4ms)  DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ?  [["id", 119]]
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   TRANSACTION (15.0ms)  commit transaction
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b]   S3 Storage (93.1ms) Deleted files by key prefix: variants/4vkiyyuj98xdrayul8li1xjey1ue/
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb]   S3 Storage (88.4ms) Deleted files by key prefix: variants/n0hplu1t8id2olzuo6xfy2cm5xzq/
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [be9b3033-8e3b-43ae-8c61-fe05889b6e6b] Performed ActiveStorage::PurgeJob (Job ID: be9b3033-8e3b-43ae-8c61-fe05889b6e6b) from Async(default) in 495.55ms
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [24396ba7-0367-457d-a9d6-a0320da253bb] Performed ActiveStorage::PurgeJob (Job ID: 24396ba7-0367-457d-a9d6-a0320da253bb) from Async(default) in 452.02ms
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1]   S3 Storage (78.5ms) Deleted files by key prefix: variants/nnadu43xtf3k4mqrbe53oa8bj9yy/
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [ef5b8011-f98d-484b-88c6-11c6567ef8b1] Performed ActiveStorage::PurgeJob (Job ID: ef5b8011-f98d-484b-88c6-11c6567ef8b1) from Async(default) in 414.11ms
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   S3 Storage (337.4ms) Deleted file from key: vs4441uwul8gqmd2yzg7lmiwissv
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   S3 Storage (84.2ms) Deleted file from key: fjgyu2bpnghwpuah4j806s9f0tik
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1]   S3 Storage (77.8ms) Deleted files by key prefix: variants/vs4441uwul8gqmd2yzg7lmiwissv/
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [398c43df-6c08-4a1a-bdb2-ff2de3c07ef1] Performed ActiveStorage::PurgeJob (Job ID: 398c43df-6c08-4a1a-bdb2-ff2de3c07ef1) from Async(default) in 482.7ms
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352]   S3 Storage (77.7ms) Deleted files by key prefix: variants/fjgyu2bpnghwpuah4j806s9f0tik/
12:29:54 web.1  | [ActiveJob] [ActiveStorage::PurgeJob] [c7ce24e2-bbbc-4134-a932-07d61b1aa352] Performed ActiveStorage::PurgeJob (Job ID: c7ce24e2-bbbc-4134-a932-07d61b1aa352) from Async(default) in 499.73ms

Solution

  • You pass empty array as param "pictures"=>[""]. That's why you delete all the pictures (replace with empty collection)

    You can choose one of the options:

    <% if @product.pictures.attached? %>
      <% @product.pictures.each do |ph| %>
        <%= f.hidden_field :pictures, multiple: true, value: ph.signed_id %>
      <% end %>
    <% end %>
    
    • prevent overwrite attachments by update in config
    config.active_storage.replace_on_assign_to_many = false