How to Use Callbacks

Learn about implementing and leveraging callbacks in our Rails application for enhanced functionality.

Active Record has a detailed set of callbacks available that allow us to run code at various points of a model’s life cycle. The use of these callbacks is hotly debated, and their proper intended use is unclear. Some developers tend to model all business processes as the life cycle of an Active Record and use callbacks to implement the business logic.

The way we suggested implementing business logic is totally different; thus, we don’t end up having many problems that callbacks could solve.

That said, there are occasions where they can be useful. Let’s talk about two that we’ve found to be common. The first is as a place for data normalization logic. The second is for managing cross-cutting operational concerns related to database access.

Normalizing data in

...