Hi there, Just a simple question I guess, but I am unable to find an anwser... How to delete a hmabtm relation? Any help will be appreciated :) Thanks, Fabrice. -- Posted via http://www.ruby-forum.com/.
gustav Paul
2006-Jul-28 14:36 UTC
[Rails] Re: Delete has_many_and_belongs_to_many relation
Fab wrote:> Hi there, > > Just a simple question I guess, but I am unable to find an anwser... > > How to delete a hmabtm relation? > > Any help will be appreciated :) > > Thanks, > Fabrice.Try this... @user = User.find(session[:current_user]) @tag = Tag.find(params[:tag_id]) @tag.users.delete(@user) where Tag habtm User I''m pretty sure that you need to pass the actual @user object, not just the id, can''t quite remember... Hope it helps :] ciao Gustav Paul gustav@rails.co.za itsdEx.com -- Posted via http://www.ruby-forum.com/.
Hi Gustav, It works perfectly ;-) Thanks a lot for your so quick answer. Best regards, Fabrice. gustav Paul wrote:> Fab wrote: >> Hi there, >> >> Just a simple question I guess, but I am unable to find an anwser... >> >> How to delete a hmabtm relation? >> >> Any help will be appreciated :) >> >> Thanks, >> Fabrice. > > Try this... > > @user = User.find(session[:current_user]) > @tag = Tag.find(params[:tag_id]) > @tag.users.delete(@user) > > where Tag habtm User > > I''m pretty sure that you need to pass the actual @user object, not just > the id, > can''t quite remember... > > Hope it helps :] > > ciao > Gustav Paul > gustav@rails.co.za > itsdEx.com-- Posted via http://www.ruby-forum.com/.