Mention the differences between the observers and callbacks in ruby on rails.

 Following are the differences between observers and callbacks in ruby on rails: –

  • Rails observers: these are same as callbacks but are used when the method is not directly associated to the life cycle of the object. It lives for a longer duration of time and can be attached or detached at any time.
  • Rails callback: the callback methods can only be called at only certain points of time in the life cycle of an object like validation, creation, updating, deletion, etc. Unlike the rails observers, the rails callback lives for only a short period of time.

Comments