Skip to content

Commit c18c3cd

Browse files
authored
Merge pull request #157 from davidalejandroaguilar/document-shrine-usage
Document usage with Shrine
2 parents 2c529c3 + d263a79 commit c18c3cd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ pirate.deep_clone include: :parrot do |original, kopy|
150150
end
151151
```
152152

153+
#### Shrine
154+
155+
Shrine is similar to Carrierwave, but you have to clear the `image_data` hash attribute from the copy, otherwise Shrine will think there's an old attachment to clean up and will delete the original image.
156+
157+
```ruby
158+
pirate.deep_clone include: [:photos, :parrot] do |original, kopy|
159+
if kopy.is_a?(Photo)
160+
kopy.image_data = nil
161+
kopy.image = original.image
162+
end
163+
end
164+
```
165+
166+
Note you're not assigning `image_data` directly, otherwise this would result in both records sharing the same asset in your storage.
167+
168+
Directly assigning `kopy.image` to `original.image` ensures you use your usual uploading mechanism, such as background jobs.
169+
153170
#### ActiveStorage
154171

155172
For ActiveStorage, you have two options: you can either make a full copy, or share data blobs between two records.

0 commit comments

Comments
 (0)