The simplest way is:
raise ActiveRecord::Rollback
which will roll the whole transaction it''s executed inside of back.
--Matt Jones
On Sep 13, 3:19 pm, Jesse Crockett
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hello, I''m beginning to test a payment method, here is an
abbreviated
> form.
>
> How can I rollback and redo the transaction if any of the save calls
> fail?
>
> def process_payment! # class Payment
> transaction do
> success = true
>
> user.blitz_interest = true
> user.points += 1
> user.blitz_contributes += DIVIDEND
>
> user.credit.pebbles += 1
>
> blitz_fund = BlitzFund.find_or_create_by_dues(DIVIDEND)
> blitz_fund.general_pool += DIVIDEND
>
> save
> user.save
> user.credit.save
> blitz_fund.save
> end
> end
> --
> Posted viahttp://www.ruby-forum.com/.