dimid dimid - 5 months ago 39
Ruby Question

Skip after_commit on destroy in rails

I'd like to skip the

after_commit
callback when
destroy
ing an object, without specifying explicitly a list of methods using the
on
syntax. I.e. something like:

after_commit :foo, except: [:destroy]

Answer

I've found a way to do it on Ruby Tips:

after_commit :foo, if: :persisted?

or for more complex conditions:

after_commit, :foo, if: Proc.new {|record| record.persisted? && [...]}
Comments