1

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 ?

4

1 に答える 1

1

これは、aasm が保存をトランザクションにラップし、例外でロールバックするためです。

現在、あなたの目的に利用できるコールバックはありませんが、次のようなものを想像できます

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

whereaction_1action_2は、例外が発生した場合でも実行されます。

問題をgithub リポジトリに追加してください。私が対応します。

于 2013-11-20T20:31:27.060 に答える