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 "<<"?
--
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
-~----------~----~----~----~------~----~------~--~---