Module: Models::AfterCommittable

Extended by:
ActiveSupport::Concern
Included in:
ApplicationRecord
Defined in:
app/concerns/models/after_committable.rb

Overview

Restores the instance-level obj.after_commit { … } ergonomic that the
retired after_commit_everywhere gem provided, on top of Rails 7.2's
ActiveRecord.after_all_transactions_commit.

The Apr 25 gem-retirement audit (commit 1458d13c) replaced 19 module-form
callsites correctly, but two instance-form ones — order.rb:565 and
taxjar_submittable.rb:46 — slipped through and only surfaced as
NoMethodErrors at runtime (AppSignal incidents #3743, #4973). Rather than
chase callsites manually each time, this concern brings the API back as a
one-line shim, so any AR instance can use the natural form:

class Foo < ApplicationRecord
def some_method
after_commit { do_thing } # runs after the surrounding txn commits,
# or immediately if no txn is open
end
end

The class-level callback DSL (after_commit :method_name, on: :update)
is unaffected — it dispatches against the class (Rails callback API), not
the instance, so there is no name collision.

Instance Method Summary collapse

Instance Method Details

#after_commit { ... } ⇒ void

This method returns an undefined value.

Schedules the block to run after every enclosing transaction commits.
If no transaction is open, the block runs synchronously. Mirrors the
after_commit_everywhere gem's instance API.

Yields:

  • runs after the surrounding txn commits (or immediately if none)



36
37
38
# File 'app/concerns/models/after_committable.rb', line 36

def after_commit(&block)
  ActiveRecord.after_all_transactions_commit(&block)
end