【发布时间】:2012-07-13 18:05:43
【问题描述】:
我有一系列记录要保存为交易的一部分。除了正常的 AR 记录外,我还在进行信用卡网关交易。如果它或 AR 交易失败,我希望一切都回滚……除了我从信用卡网关返回的失败交易的数据(原因、日期等)。类似的东西
def pay
Payment.transaction do
payment.save
other.save
result = credit_card.purchase # this does the gateway transaction, no database stuff
if result.failure
raise ActiveRecord::Rollback
result.save # this is the part I want to always save
end
another.save
end
end
有没有办法从失败回滚中排除事务中的特定部分?
Rails 3.2.5,MySQL 5.1
【问题讨论】:
标签: ruby-on-rails-3 transactions