Skip to content

Commit

Permalink
Document usage with Shrine
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Feb 1, 2025
1 parent 2c529c3 commit d263a79
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ pirate.deep_clone include: :parrot do |original, kopy|
end
```

#### Shrine

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.

```ruby
pirate.deep_clone include: [:photos, :parrot] do |original, kopy|
if kopy.is_a?(Photo)
kopy.image_data = nil
kopy.image = original.image
end
end
```

Note you're not assigning `image_data` directly, otherwise this would result in both records sharing the same asset in your storage.

Directly assigning `kopy.image` to `original.image` ensures you use your usual uploading mechanism, such as background jobs.

#### ActiveStorage

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

0 comments on commit d263a79

Please sign in to comment.