dimid dimid - 1 year ago 181
Ruby Question

Skip after_commit on destroy in rails

I'd like to skip the

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

after_commit :foo, except: [:destroy]

Answer Source

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? && [...]}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download