Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created July 10, 2011 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottwb/1074704 to your computer and use it in GitHub Desktop.
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.
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