Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -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|
Expand All @@ -212,19 +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
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
})
end
end
end
```

##### Shallow copy example
Expand Down