Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

_destroy doesn't work #27

Closed
phlegx opened this issue Apr 11, 2011 · 8 comments · Fixed by #88
Closed

_destroy doesn't work #27

phlegx opened this issue Apr 11, 2011 · 8 comments · Fixed by #88
Labels

Comments

@phlegx
Copy link

phlegx commented Apr 11, 2011

Hi!

Good work Ryan!!! But something goes wrong in my project. I cannot destroy an image (I use carrierwave). If I click on "remove" the _destroy input tag is set to "1" but the image remains on save. Have you an idea? I have added "accepts_nested_attributes_for :assets, :allow_destroy => true" to the asset model and the other code is ok.

I use:

Rails 3.0.3
Ruby 1.9.2

Bye

@ryanb
Copy link
Owner

ryanb commented Apr 12, 2011

That's strange, I'm not sure what the issue could be. Do you have attr_accessible in the image model? You can try adding _destroy there but you shouldn't have to.

You can check out the nested_form branch of the complex-form-example project for a working example.
https://github.com/ryanb/complex-form-examples/tree/nested_form

@ryanb ryanb closed this as completed Apr 12, 2011
@phlegx
Copy link
Author

phlegx commented Apr 12, 2011

How can I debug "the model" to find the problem? I use the following in the parent model:

attr_accessible ..., :avatars_attributes

has_many :avatars, :as => :avatarable, :dependent => :destroy   
accepts_nested_attributes_for :avatars, :allow_destroy => true

[SOLVED] Problem solved. I have moved the code above to the superclass. If the code is in the subclass model than the destroy doesn't work!

@ryanb
Copy link
Owner

ryanb commented Apr 14, 2011

Glad you got it solved, that's a strange bug but thank you for reporting.

@cmezak
Copy link

cmezak commented May 12, 2011

It might be good to mention in the readme the need for :allow_destroy => true in the accepts_nested_attributes_for call.

@ryanb
Copy link
Owner

ryanb commented May 24, 2011

Good point. I'll reopen this for that readme addition.

@ryanb ryanb reopened this May 24, 2011
@tralles
Copy link

tralles commented Aug 31, 2011

i had the same problem in rails 3.1.0.rc8 - but to add :allow_destroy => true does the trick - also today in rails 3.1 …
thanks for this gem :)

@derekprior
Copy link
Contributor

See pull request 88 for the readme update.

@lest
Copy link
Collaborator

lest commented Jun 6, 2012

#88 was merged. Thanks!

@lest lest closed this as completed Jun 6, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants