Skip to content

Instantly share code, notes, and snippets.

@julesfern
Created April 17, 2009 19:02
Show Gist options
  • Select an option

  • Save julesfern/97197 to your computer and use it in GitHub Desktop.

Select an option

Save julesfern/97197 to your computer and use it in GitHub Desktop.
def beneficiary_relationships=(arg)
raise ArgumentError, "beneficiaries must be set as a hash keyed with relationship id's, with values as booleans" unless arg.is_a?(Hash)
if new_record?
@relationships_to_associate = arg
else
enable_ids = arg.select {|key, value| ["true","1"].include?(value.to_s) }.map {|k,v| k.to_i }
relationship_list = Relationship.all(:origin_user_id=>user_id, :id=>enable_ids)
self.relationships.clear
self.relationships = relationship_list
save
end
end
after :save do
if r = @relationships_to_associate
self.beneficiary_relationships = r
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment