mongoid-paperclip
mongoid-paperclip copied to clipboard
destroy or destroy all on embedded documents doesnt destroy all object.
destroy or destroy all on embedded documents doesnt destroy all object.
person.rb
class Person embeds_many :pictures, :cascading_callback => true end
picture.rb
class Picture embedded_in Person
has_mongoid_attached_file :picture end
in PersonsController
def delete_pictures
if @person.pictures.present? @person.pictures.destroy_all end
end
If beforehand the person database have pictures, this WON'T WORK Properly, somehow. Destroy doesnt delete all of my picture objects.
Even with
@person.pictures.each do |p| p.destroy end
Doesnt do the trick.
My own hack is to use this:
Controller while @person.pictures.present?
@person.pictures.destroy_all doesnt work either, coz after that the pictures array is empty, when on next reload not.
@person.pictures.each do |p| @person.pictures.destroy end end
Can somebody explain to me what did i do wrong?
Thanks!
+1
+1