In the web app I'm currently working on users can upload multiple images - and can also delete them later on.
Is there a way to easily delete uploaded files in file-column? The deletion should affect the database and the file structure of course.
I didn't find any documentation for that...
I find the easiest way to do that is to have a main record that has_one or has_many images. Each image has an ID, parent_id and file_column field. Then, all you need to do is destroy any image record. I believe that takes care of the rest
protected
def delete_img_file
....some code to delete the image here ...
.... self.file_column should give you the filename/path (however thats
stored in there, dont know the plugin you used)....
end
protected
def delete_img_file
....some code to delete the image here ...
.... self.file_column should give you the filename/path (however thats
stored in there, dont know the plugin you used)....
end
end
The reason why file column didn't delete the files automatically when I deleted an entry was because I used entry.delete instead of entry.destroy. The latter one kills all uploaded files also...
Thanks for your help.
I should have bolded the word *destroy* in my reply