-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rake task to regerate derivatives
- Loading branch information
1 parent
0efd05d
commit 7759507
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace :banner_images do | ||
desc "Generates derivates for banner images" | ||
task generate_derivatives: :environment do | ||
BannerImage.find_each do |banner_image| | ||
attacher = banner_image.image_attacher | ||
|
||
next unless attacher.stored? | ||
|
||
attacher.create_derivatives | ||
|
||
begin | ||
attacher.atomic_persist # persist changes if attachment has not changed in the meantime | ||
rescue Shrine::AttachmentChanged, # attachment has changed | ||
ActiveRecord::RecordNotFound # record has been deleted | ||
attacher.delete_derivatives # delete now orphaned derivatives | ||
end | ||
end | ||
end | ||
end |