Posted almost 9 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.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Henning Koch
Last edit:
about 5 years ago
Keywords:
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