Niklas Nson
2011-Apr-15 05:42 UTC
accepts_nested_attributes_for and _destroy not working (but no error messages)
I have a has_many association and does some adding throug a nested form, i can add objects (images) and edit text this works fine. But when i try to delete items nothing happens. This is what my log looks like: Started POST "/photosets/168" for 127.0.0.1 at Fri Apr 15 07:34:04 +0200 2011 Processing by PhotosetsController#update as HTML Parameters: {"commit"=>"Ändra Photoset", "authenticity_token"=>"18nwmbNhushmQoXOLafzzjodbCoCtQMu22MG772Y8Xg=", "utf8"=>"✓", "photoset"=>{"title"=>"en ny titel", "photosetassets_attributes"=>{"6"=>{"_destroy"=>"false"}, "7"=>{"_destroy"=>"false"}, "8"=>{"_destroy"=>"false"}, "9"=>{"_destroy"=>"false"}, "0"=>{"id"=>"971", "_destroy"=>"false"}, "1"=>{"id"=>"972", "_destroy"=>"false"}, "2"=>{"id"=>"975", "_destroy"=>"false"}, "3"=>{"id"=>"976", "_destroy"=>"1"}, "4"=>{"_destroy"=>"false"}, "5"=>{"_destroy"=>"false"}}, "credit_tokens"=>"1", "description"=>"dsadsad", "genre_ids"=>["1", "2", "3"]}, "id"=>"168"} And it looks to me as "3"=>{"id"=>"976", "_destroy"=>"1"} is marked for _destroy here. If i in the console write: p = Photoset.last f.update_attributes("photosetassets_attributes" => {"id" => "976", "_destroy" => "1"}) p = Photoset.last.photosetassets => [#<Photosetasset id: 971, image: "20090818-img_0024.jpg", photoset_id: 168, created_at: "2011-04-15 05:02:26", updated_at: "2011-04-15 05:02:26">, #<Photosetasset id: 972, image: "arvidsson0161.jpg", photoset_id: 168, created_at: "2011-04-15 05:02:26", updated_at: "2011-04-15 05:02:26">, #<Photosetasset id: 975, image: "2009_01_04_img_00000323.jpg", photoset_id: 168, created_at: "2011-04-15 05:23:38", updated_at: "2011-04-15 05:23:38">] And its deleted. Please advice me what to do, have been working on this for the last nights and i cant see whats wrong with it. /Niklas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
skt
2011-Apr-15 06:28 UTC
Re: accepts_nested_attributes_for and _destroy not working (but no error messages)
Couple things you can try - 1. Where you have _destroy="false" replace that with _destroy="0" - just in case something is throwing that parser out of whack 2. Try _delete instead of _destroy - been a while but I remember in one of my setups _delete worked but not _destroy -S On Apr 14, 10:42 pm, Niklas Nson <niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:> I have a has_many association and does some adding throug a nested > form, i can add objects (images) and edit text this works fine. But > when i try to delete items nothing happens. This is what my log looks > like: > > Started POST "/photosets/168" for 127.0.0.1 at Fri Apr 15 07:34:04 > +0200 2011 > Processing by PhotosetsController#update as HTML > Parameters: {"commit"=>"Ändra Photoset", > "authenticity_token"=>"18nwmbNhushmQoXOLafzzjodbCoCtQMu22MG772Y8Xg=", > "utf8"=>"✓", "photoset"=>{"title"=>"en ny titel", > "photosetassets_attributes"=>{"6"=>{"_destroy"=>"false"}, > "7"=>{"_destroy"=>"false"}, "8"=>{"_destroy"=>"false"}, > "9"=>{"_destroy"=>"false"}, "0"=>{"id"=>"971", "_destroy"=>"false"}, > "1"=>{"id"=>"972", "_destroy"=>"false"}, "2"=>{"id"=>"975", > "_destroy"=>"false"}, "3"=>{"id"=>"976", "_destroy"=>"1"}, > "4"=>{"_destroy"=>"false"}, "5"=>{"_destroy"=>"false"}}, > "credit_tokens"=>"1", "description"=>"dsadsad", "genre_ids"=>["1", > "2", "3"]}, "id"=>"168"} > > And it looks to me as "3"=>{"id"=>"976", "_destroy"=>"1"} is marked > for _destroy here. > > If i in the console write: > p = Photoset.last > f.update_attributes("photosetassets_attributes" => {"id" => "976", > "_destroy" => "1"}) > p = Photoset.last.photosetassets > > => [#<Photosetasset id: 971, image: "20090818-img_0024.jpg", > photoset_id: 168, created_at: "2011-04-15 05:02:26", updated_at: > "2011-04-15 05:02:26">, #<Photosetasset id: 972, image: > "arvidsson0161.jpg", photoset_id: 168, created_at: "2011-04-15 > 05:02:26", updated_at: "2011-04-15 05:02:26">, #<Photosetasset id: > 975, image: "2009_01_04_img_00000323.jpg", photoset_id: 168, > created_at: "2011-04-15 05:23:38", updated_at: "2011-04-15 05:23:38">] > > And its deleted. > > Please advice me what to do, have been working on this for the last > nights and i cant see whats wrong with it. > > /Niklas-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.