ryanb/nested_form — Issue #117: Mongoid _destroy is not deleted embedded document using nested_form gem
Author: jerryshen
Created: 2011-11-17 05:15:09+00:00
State: open

I am on Rails 3.1, Mongoid 2.3.3, and using the nested_form gem. In my form, I have the nested_form link_to_add and link_to_remove set up to add and remove an embedded document in my model. The link_to_add helper method works great, but the link_to_remove help method changes are not persisted in MongoDB. In the rails output, I can see the JSON parameter passed to Mongoid has the _destroy: 1 value set but the change is not saved to MongoDB.

Here is the model

class Product
include Mongoid::Document
include Mongoid::Timestamps

field :name, :type => String

embeds_many :photos, :as => :photogenic, :cascade_callbacks => true

accepts_nested_attributes_for :photos,
:reject_if => proc { |attributes| attributes['data'].blank? },
:allow_destroy => true

end

I'm sure I missed something, but I haven't been able to figure out why the embedded document isn't removed.