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
end
and adding an intention is done by:
@book.users << User.find(session[:user_id])
if @book.save!
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])}
if @book.save!
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 “<<”?