aasm: 'after' callback should be triggered after saving in DB
Continuing the discussion from http://stackoverflow.com/questions/20071940/aasm-error-in-after-event-callback-cancels-the-event/20106381?noredirect=1#20106381
- When firing an event with ‘!’, let aasm save the new state even if there’s an exception in the after callbacks. (== the ‘after’ callback is fired AFTER persisting the new state.) If there’s a problem getting to the new state (e.g. failing guard, exception on ‘before’ actions…) the new state will not be saved in DB of course. If the current ‘after’ callback is to be preserved, you can still create a new ‘after_save’ callback for this purpose.
- @alto also suggested “assure” event callback to be fully executed even in case of an exception.
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.
Thanks David.
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 1
- Comments: 17 (9 by maintainers)
@phuongnd08 Yes and no. The
after_commit
hook has been moved fromstate
toevent
definitions in AASM version4.0.0
(see #112 for details on this).