Mention what is the difference between the Observers and Callbacks in Ruby on Rails?

Technology CommunityCategory: Ruby on RailsMention what is the difference between the Observers and Callbacks in Ruby on Rails?
VietMX Staff asked 3 years ago
  • Rails Observers: Observers is same as Callback, but it is used when method is not directly associated to object lifecycle. Also, the observer lives longer, and it can be detached or attached at any time. For example, displaying values from a model in the UI and updating model from user input.
  • Rails Callback: Callbacks are methods, which can be called at certain moments of an object’s life cycle for example it can be called when an object is validated, created, updated, deleted, A call back is short lived. For example, running a thread and giving a call-back that is called when thread terminates