0
我正在編寫一個活動記錄事務的測試。 引發錯誤的方法如下所示;SystemStackError:堆棧級別太深 - 數據庫事務
after_save :process_transaction_fees
def process_transaction_fees
if self.status == "SUCCESS"
transaction_fees = 0.0299 #improve after success
merchant = Business.find_by_id(self.business_id)
transaction_charges = (self.amount * transaction_fees).to_f
balance = merchant.balance
balance_before = merchant.balance
balance_after = (balance_before.to_f - transaction_charges.to_f)
merchant_deposit = BusinessTransaction.new(business_id: self.business_id ,amount: transaction_charges, balance_before: balance_before, balance_after: balance_after, status: "SUCCESS")
merchant.balance = (balance.to_f - transaction_charges.to_f)
ActiveRecord::Base.transaction do
merchant.save!
merchant_deposit.save!
end
end
end
不過,我不斷收到錯誤SystemStackError: stack level too deep
就行merchant.save!
。
這可能是什麼原因造成的?