Displaying 1 result from an estimated 1 matches for "intersect_or_remove_group".
2009 Feb 04
2
delete_if does not work on associations
...Group < ActiveRecord::Base
  has_many :memberships, :dependent => :destroy
  has_many :users, :through => :memberships
  ...
end
This is the controller method, trying to use delete_if. Although some
elements are removed (s2 < s1), the save method does not update the
association.
def intersect_or_remove_group
    other_group = Group.find(params[:group_id])
    s1 = @group.users.size
    case params[:submit]
      when "Intersect"
        @group.users.delete_if  { |u| !other_group.users.include?(u) }
      when "Remove"
        @group.users.delete_if { |u| other_group.users.include?(u...