In my Rails app, I would like to update my database once all versions of an uploaded image are created and stored. Is there a callback that ensures that recreate_versions! is complete?
Background: I allow users to rotate images that they upload to my site. I show a preview of the rotation using webkit-transform and only actually rotate the image using imagemagick when the user saves the image. However, to prevent holding up the app until the image versioning is complete, I do this in a background task and continue to apply the rotation by applying the webkit-transform. I need to know when the image has been fully rotated before I pull the correct image from the database (rather than rotate the image on the client side).
P.S. I looked at this page: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-use-callbacks, but I also saw that these callbacks are called after ever version, not after all versioning is complete.
I was able to solve this problem by using after_save callback, may be this will help you too
after_save :update_avatar_url
def update_avatar_url
update_column(:avatar, avatar.thumb.url)
end
update_column does not trigger after_save callback thus there is no infinite recursion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With