Skip to content

Commit

Permalink
Add AS full copy example for rails 6 [ci skip]
Browse files Browse the repository at this point in the history
Resolves #118
  • Loading branch information
moiristo committed Apr 29, 2020
1 parent 4ef36af commit 8dcd6ec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions readme.md
Expand Up @@ -157,6 +157,7 @@ For ActiveStorage, you have two options: you can either make a full copy, or sha
##### Full copy example

```ruby
# Rails 5
pirate.deep_clone include: :parrot do |original, kopy|
if kopy.is_a?(Pirate) && original.avatar.attached?
ActiveStorage::Downloader.new(original.avatar).download_blob_to_tempfile do |tempfile|
Expand All @@ -168,6 +169,19 @@ pirate.deep_clone include: :parrot do |original, kopy|
end
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

0 comments on commit 8dcd6ec

Please sign in to comment.