Delete has_many_and_belongs_to_many relation

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 :slight_smile:

Thanks,
Fabrice.

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 :slight_smile:

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 P.
[email protected]
itsdEx.com

Hi Gustav,

It works perfectly :wink:
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 :slight_smile:

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 P.
[email protected]
itsdEx.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs