From fbe52f69e5d96f1a1045c15399a04ff5b7f49965 Mon Sep 17 00:00:00 2001 From: Ameen Khan Date: Fri, 9 Oct 2026 11:15:18 +0530 Subject: [PATCH 1/2] Fix ActiveStorage example for Rails 6.1+ --- readme.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index b575817..55d6902 100644 --- a/readme.md +++ b/readme.md @@ -213,16 +213,14 @@ pirate.deep_clone include: :parrot do |original, kopy| end end -# Rails 6 +# Rails 6.1 pirate.deep_clone include: :parrot do |original, kopy| if kopy.is_a?(Pirate) && original.avatar.attached? - original.avatar.open do |tempfile| kopy.avatar.attach({ - io: File.open(tempfile.path), - filename: original.avatar.blob.filename, - content_type: original.avatar.blob.content_type + io: StringIO.new(original.avatar.download), + filename: original.avatar.filename, + content_type: original.avatar.content_type }) - end end end ``` From 1a2b354336cb8408932cfd662330849492d69c8f Mon Sep 17 00:00:00 2001 From: Ameen Khan Date: Fri, 9 Oct 2026 15:49:35 +0530 Subject: [PATCH 2/2] Consolidate ActiveStorage examples in README --- readme.md | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/readme.md b/readme.md index 55d6902..c80bea6 100644 --- a/readme.md +++ b/readme.md @@ -173,10 +173,10 @@ For ActiveStorage, you have two options: you can either make a full copy, or sha ##### Full copy example ```ruby -# Rails 5.2, has_one_attached example 1 +# has_one_attached example 1 pirate.deep_clone include: [:parrot, :avatar_attachment, :avatar_blob] -# Rails 5.2, has_one_attached example 2 +# has_one_attached example 2 pirate.deep_clone include: :parrot do |original, kopy| if kopy.is_a?(Pirate) && original.avatar.attached? attachment = original.avatar @@ -187,7 +187,7 @@ pirate.deep_clone include: :parrot do |original, kopy| end end -# Rails 5.2, has_many_attached example 1 (attach one by one) +# has_many_attached example 1 (attach one by one) pirate.deep_clone include: :parrot do |original, kopy| if kopy.is_a?(Pirate) && original.crew_members_images.attached? original.crew_members_images.each do |attachment| @@ -199,7 +199,7 @@ pirate.deep_clone include: :parrot do |original, kopy| end end -# Rails 5.2, has_many_attached example 2 (attach bulk) +# has_many_attached example 2 (attach bulk) pirate.deep_clone include: :parrot do |original, kopy| if kopy.is_a?(Pirate) && original.crew_members_images.attached? all_attachments_arr = original.crew_members_images.map do |attachment| @@ -212,17 +212,6 @@ pirate.deep_clone include: :parrot do |original, kopy| kopy.crew_members_images.attach(all_attachments_arr) # attach all at once end end - -# Rails 6.1 -pirate.deep_clone include: :parrot do |original, kopy| - if kopy.is_a?(Pirate) && original.avatar.attached? - kopy.avatar.attach({ - io: StringIO.new(original.avatar.download), - filename: original.avatar.filename, - content_type: original.avatar.content_type - }) - end -end ``` ##### Shallow copy example