Carrierwave is an awesome gem for making file uploads and image processing easy within Ruby on Rails. I’m currently testing it out with MongoDB and GridFS using Mongoid and it’s working almost seamlessly. What took me a days of work with PHP/Zend Framework now takes me an hour in Rails; just awesome, I think I might actually go and relax for a couple of hours with the time I’ve saved =).
The problem I’m having at the moment is that I’m mounting files in an embedded document; when I delete the parent document, the delete does not bubble down the the embedded document. This results in the files not been deleted from GridFS even though the parent document has been destroyed.
This is how I got around the issue. By setting a hook on the after_destroy callback method in the parent model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 2 3 4 5 6 7 8 9