質問

I have an aasm event which looks like this:

event :close do
  transitions from: :normal, to: :closed
  after do
    action_1(...)
    action_2(...)
  end
end

now, I've noticed that when I call close! and there's an error on action2, the event is not saved in the db. I guess that the order of things is 1. transition of the instance 2. after callbacks 3. save

except for catching the error under the 'after' block level, is there a callback that is triggered after the 'save' which I can use ?

役に立ちましたか?

解決

The reason for this is that aasm wraps the save into a transaction, which rolls back on exception.

Currently there is no callback available for your purpose, but I could imagine something like

event :close do
  transitions from: :normal, to: :closed
  assure do
    action_1(...)
    action_2(...)
  end
end

where action_1 and action_2 will be executed even in case of an exception.

Please add an issue to the github repository and I will take care of that.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top