Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting records from embeds_many relation, doesn't destroy record. #24

Open
tcopple opened this issue Mar 12, 2012 · 0 comments
Open

Comments

@tcopple
Copy link

tcopple commented Mar 12, 2012

When I try to delete an attachment through an 'embeds_many' relation, using the _delete key generated by a form, the attachment is deleted but the record remains with it's paperclip
fields set to nil. How do I delete the record from the relation?

class User
  include Mongoid::Document

  embeds_many :photos, cascade_callbacks => true
  accepts_nested_attributes_for :photos, :allow_destroy => true
end

class Photo
  include Monogoid::Document

  has_mongoid_attached_file :attachment
  embedded_in :shopping_center, :inverse_of => :photos
end

When I submit my form to remove the first attachment here's the request that's generated:

{..., "user"=>{
        "photos_attributes"=>{
           "0"=>{"_destroy"=>"1", "id"=>"4f5e30440cc47d6c5400002d"}, 
           "1"=>{"_destroy"=>"false", "id"=>"4f5e30440cc47d6c5400002e"}
         }
       }, 
...}

However when the request is processed through the controller:

class UsersController < ApplicationController
  def update
    @user.= User.find(params[:id])
    @user.update_attributes(params[:user]

    #rendering code here
   end
end

Paperclip issues the appropriate Deleting attachments messages, but then when I view the model, the record still exists. The underlying file has been removed, and all the paperclip fields on the Photo class have been set to nil.

How do I ensure the record is removed from the relation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant