Created
July 10, 2011 17:08
-
-
Save scottwb/1074704 to your computer and use it in GitHub Desktop.
Ignore NotFound exceptions from CarrierWave when destroying models with dangling references to missing files.
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
class User < ActiveRecord::Base | |
mount_uploader :avatar, AvatarUploader | |
# Override to silently ignore trying to remove missing | |
# previous avatar when destroying a User. | |
def remove_avatar! | |
begin | |
super | |
rescue Fog::Storage::Rackspace::NotFound | |
end | |
end | |
# Override to silently ignore trying to remove missing | |
# previous avatar when saving a new one. | |
def remove_previously_stored_avatar | |
begin | |
super | |
rescue Fog::Storage::Rackspace::NotFound | |
@previous_model_for_avatar = nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment