What’s the big picture difference between observers and callbacks? When and where to use which one?
What’s the big picture difference between observers and callbacks? When and where to use
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s about separation of concerns.
Observers allow you to factor out code that doesn’t really belong in models. For example, a
Usermodel might have a callback that sends a registration confirmation email after the user record is saved, but you don’t really want this code in the model because it’s not directly related to the model’s purpose.Observers allow you to have that clean separation because you don’t have all that callback code in your models. Observers depend a model (or models), not the other way around.