Posted over 8 years ago. Visible to the public. Linked content.

Order of the state_machine callback chain and how to abort it

  1. before transition
  2. before validation
  3. after validation
  4. before save
  5. after save
  6. after transition

Aborting the callback chain

  • You can interrupt the callback chain by returning false in before_transition.
  • You can not prevent the record from being saved by manually adding an validation error during before_transition.
  • You can rollback the database update by raising an error in after_transition. The error will bubble up to the caller, no changes will be saved.
  • You can not interrupt the callback chain by returning false in after_transition.

Similar cards

Also see Cancel the ActiveRecord callback chain.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Henning Koch
Last edit:
almost 5 years ago
cancel, callbacks
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more