Hi, I''m sorry to post such a trivial question but... I have a table for comments. And I can fill it normally: @tab = Tab.find(params[:id]) @tab.comments.create(:body => ''This is the body 1'') I am able to correctly see their contents this way: puts @tab.comments[0].body I can also see its ID with: puts @tab.comments[0].id (22 for example) So it is fine to add rows and check the right contents. BUT I am able to delete all the comments with: @tab.comments.delete_all However I am unable to delete a row in the table... @tab.comments.delete(22) I''ve tried several things but as far as I know from some examples that should work. I''m I doing something very wrong? Thanks once again. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6 Dec 2007, at 22:58, comopasta Gr wrote:> > I am able to delete all the comments with: > @tab.comments.delete_all > > However I am unable to delete a row in the table... > @tab.comments.delete(22) >On an association collection like you''ve got, delete_all deletes all the rows in the collection, but delete deletes the object you pass in - it doesn''t operate on ids. If you want to delete a comment by id, you need to use the delete method on the class (ie Comment.delete 22 Fred> I''ve tried several things but as far as I know from some examples that > should work. > > I''m I doing something very wrong? > > Thanks once again. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> you need to use the delete method on the class (ie Comment.delete 22Thank you so much for the explanation Fred. Indeed it worked like that. Cheers! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I am able to delete all the comments with: > @tab.comments.delete_all > > However I am unable to delete a row in the table... > @tab.comments.delete(22) > > I''ve tried several things but as far as I know from some examples that > should work. > > I''m I doing something very wrong? > > Thanks once again.Actually @tab.comments will return an array. "delete" method is available for ruby Array class. But there is no method called "delete_all" for Array class. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 7 Dec 2007, at 12:40, Karthi kn wrote:> > >> I am able to delete all the comments with: >> @tab.comments.delete_all >> >> However I am unable to delete a row in the table... >> @tab.comments.delete(22) >> >> I''ve tried several things but as far as I know from some examples >> that >> should work. >> >> I''m I doing something very wrong? >> >> Thanks once again. > > Actually @tab.comments will return an array. > "delete" method is available for ruby Array class. > > But there is no method called "delete_all" for Array class. >Actually it returns an AssociationProxy that''s pretending to be an array. Fred> > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---