Namespace
Methods
I
R
T
W
Class Public methods
included(base)
# File activerecord/lib/active_record/transactions.rb, line 9
def self.included(base)
  base.extend(ClassMethods)
  base.class_eval do
    [:destroy, :save, :save!].each do |method|
      alias_method_chain method, :transactions
    end
  end
end
Instance Public methods
rollback_active_record_state!()

Reset id and @new_record if the transaction rolls back.

# File activerecord/lib/active_record/transactions.rb, line 204
def rollback_active_record_state!
  id_present = has_attribute?(self.class.primary_key)
  previous_id = id
  previous_new_record = new_record?
  yield
rescue Exception
  @new_record = previous_new_record
  if id_present
    self.id = previous_id
  else
    @attributes.delete(self.class.primary_key)
    @attributes_cache.delete(self.class.primary_key)
  end
  raise
end
transaction(&block)

See ActiveRecord::Transactions::ClassMethods for detailed documentation.

# File activerecord/lib/active_record/transactions.rb, line 187
def transaction(&block)
  self.class.transaction(&block)
end
with_transaction_returning_status(method, *args)

Executes methodwithin a transaction and captures its return value as a status flag. If the status is true the transaction is committed, otherwise a ROLLBACK is issued. In any case the status flag is returned.

This method is available within the context of an ActiveRecord::Base instance.

# File activerecord/lib/active_record/transactions.rb, line 226
def with_transaction_returning_status(method, *args)
  status = nil
  self.class.transaction do
    status = send(method, *args)
    raise ActiveRecord::Rollback unless status
  end
  status
end