I'm on rails 3.0.8 and trying to use the after_commit callback.
It's defined here: https://github.com/rails/rails/blob/v3.0.8/activerecord/lib/active_record/transactions.rb#L210
It's mentioned as one of the callbacks here: https://github.com/rails/rails/blob/v3.0.8/activerecord/lib/active_record/callbacks.rb#L22
Consider this:
class Car < ActiveRecord::Base
after_commit do
# this doesn't execute
end
after_commit :please_run
def please_run
# nor does this
end
end
Any ideas why it doesn't work? I assume I'm using it correctly.
If you're experimenting with this in your test suite, you'll have to set self.use_transactional_fixtures = false
for that class. By default, Rails executes a test suite inside a transaction and does a rollback at the end to clean up. It makes your tests fast, but if you rely on controlling transactions yourself or this callback, it doesn't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With