WAT!! ActiveRecord Callbacks
summary
ActiveRecord callbacks cause concrete failures: a before callback returning false aborts save so a test expecting no activation instead flips because the callback returns false; creating user records in tests triggers thousands of delayed jobs and multiplies test time by about ten minutes; historically after_commit suppresses exceptions pre-4.2 so background work can silently fail (Rails 4.2 changes this). Use callbacks only for logic that reads the object's internal state, not to pass external parameters or trigger unreliable side effects.
AI-written summary · about
chapters (6)
- 0:00Introduction and context
- 1:43Understanding callbacks
- 2:54Debugging unexpected behavior
- 5:46Performance impacts
- 8:04Exception handling risks
- 9:38Best practices for callbacks
related talks
29mBetter callbacks in Rails 5
44mDo You Need That Validation? Let Me Call You Back About It
41mAn Intervention for ActiveRecord
33mThe Very Hungry Transaction
29mPutting Rails in a corner: Understanding database isolation
48mThe Circle Of Lifecycle Events
27mFake Your Test Away: How To Abuse Your Test Doubles
36mRails: Shadow Facets of Concurrency
