I create an infinite callback loop when I need to update an attribute during an after_commit, :on => :create
. It only occurs if I need to update an attribute of the object during this callback, though. Is there a way to prevent this? Can I somehow force a model to reload itself so it knows that it is performing an update rather than a create?
class Doc < ActiveRecord::Base
after_commit :generate, :on => :create
...
def generate
# some logic here that requires this model to be saved in the db
self.update_attributes(:filename => filename) # Infinite loop begins here.
end
end
generate
method.after_commit
should be trigged onlyon: :create
as the declaration, but in fact it's trigged even it's updated.