Forum: Ruby on Rails remove habtm item?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (Guest)
on 2007-04-01 23:17
I'm making a website for a book club, and I'm trying to arrange it so
that members can indicate their intention to attend the discussion of a
given book.  I've got that working, but I'm not able to remove these
"votes" later on.  I have

  class Book < ActiveRecord::Base
    has_and_belongs_to_many :users

and adding an intention is done by:

  @book.users << User.find(session[:user_id])

That works fine.  However, I'm not too clear on how to *remove* an
intention.  Right now, I'm doing this as

  @book.users.delete_if {|u| u == User.find(session[:user_id])}

and, although the "true" part of the save is executed (it flashes), the
book.users array is not actually changed.

Q: Is there a standard way to do this sort of thing, sort of the reverse
of "<<"?
94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-04-02 02:21
I'm answering my own question, to help anyone who happens upon it...

The solution (gleaned from
is to do

   @book = Book.find(params[:id])
   @user = User.find(session[:user_id])
This topic is locked and can not be replied to.