Skip to content

Instantly share code, notes, and snippets.

@1990prashant
Created March 2, 2016 08:24
Show Gist options
  • Save 1990prashant/3ccf1c1c18ec7996741b to your computer and use it in GitHub Desktop.
Save 1990prashant/3ccf1c1c18ec7996741b to your computer and use it in GitHub Desktop.
To delete paperclip attachment
def remove_image
@user.image.clear #This is optional you can skip it
@user.image.destroy #This line delete image from paperclip
# Now you need to update image url because destroy is not remove url so you need to update image field
@user.update_attributes(image: nil)
end
#Note: You can directaly update your image field but it doesn't delete image from storage.
#Note1: Controller name may be changed according to your requirement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment