Skip to content

Instantly share code, notes, and snippets.

@bighi
Created April 20, 2012 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bighi/2431514 to your computer and use it in GitHub Desktop.
Save bighi/2431514 to your computer and use it in GitHub Desktop.
def merge(people)
people.each do |id|
person = Person.find(id)
return false unless person.account.id == self.account.id
self.transaction do
person.financial_transactions.each do |ft|
ft.person = self
errors[:base] << "Erro ao salvar financial transaction" unless ft.save!
end
person.financial_accounts.each do |fa|
fa.person = self
errors[:base] << "Erro ao salvar financial account" unless fa.save!
end
person.force_destroy = true
error[:base] << "Erro ao remover cliente / fornecedor" unless person.destroy
raise ActiveRecord::Rollback unless errors.empty?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment