💎 Ruby on Rails
Beginner
What are ActiveRecord callbacks?
Answer
ActiveRecord callbacks are hooks that execute code at specific points in an object's lifecycle. Order for save: before_validation → after_validation → before_save → before_create/update → (SQL) → after_create/update → after_save → after_commit. Useful callbacks: before_save :downcase_email, after_create :send_welcome_email, before_destroy :cancel_subscriptions. Be careful with callbacks — they can make models hard to test and understand. Consider service objects for complex business logic instead.
Previous
What are ActiveRecord validations?
Next
What is the difference between render and redirect_to in Rails?