You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've spent the entire day trying to figure out how to successfully delete individual files, which were uploaded and stored as an array/Json in MySQL. I'm completely puzzled and need some help.
I have been unable to find a solution on the net that works.
I upload a list of files to an album, say 150 images. Then I want to delete something like 5 images. How can I do that? I don't want to delete the entire list.
I would expect to be able to call something like album.remove_images([1.jpg,2.jpg,3.jpg]), or even use indexes. Using indexes doesn't work because if you iterate over the list as you delete items the index count changes.
Doing something like the following only allows the user to delete a single file at a time, which would require multiple hits to the database and be a serious headache of they want to remove like 35 of the 150 files.
def remove_image_at_index(index)
remain_images = @gallery.images # copy the array
deleted_image = remain_images.delete_at(index) # delete the target image
deleted_image.try(:remove!) # delete image from S3
@gallery.images = remain_images # re-assign back
end
I'm totally baffled, please help. Thanks.
The text was updated successfully, but these errors were encountered:
I've spent the entire day trying to figure out how to successfully delete individual files, which were uploaded and stored as an array/Json in MySQL. I'm completely puzzled and need some help.
I have been unable to find a solution on the net that works.
I upload a list of files to an album, say 150 images. Then I want to delete something like 5 images. How can I do that? I don't want to delete the entire list.
I would expect to be able to call something like album.remove_images([1.jpg,2.jpg,3.jpg]), or even use indexes. Using indexes doesn't work because if you iterate over the list as you delete items the index count changes.
Doing something like the following only allows the user to delete a single file at a time, which would require multiple hits to the database and be a serious headache of they want to remove like 35 of the 150 files.
I'm totally baffled, please help. Thanks.
The text was updated successfully, but these errors were encountered: