Shrine gem - how to delete uploaded images from s3
Asked Answered
S

1

7

Apparently :remove_attachment plugin does the trick with checking and submitting but how can I call the method from the controller?

Socialite answered 28/7, 2016 at 13:19 Comment(0)
A
12

All plugins which allow you to set up form fields (remove_attachment, remote_url, data_uri, ...) work in a way that they add getters and setters to your models, so if you have a Photo model with "image" attachment, you can do photo.remove_image = true.

However, for removing attachments in Ruby code you don't need the remove_attachment plugin, you can just assign the attachment to nil:

photo.image = nil
# or
photo.update(image: nil)
Angola answered 29/7, 2016 at 6:33 Comment(1)
I got it now. Just deleting a record from your database table with image_data column deletes the image from s3 as well. Thanks.Socialite

© 2022 - 2024 — McMap. All rights reserved.