Lesser Model Callbacks — Refactoring Rails the Clean Way

Callbacks are double edge swords. They are predictable actions that always executes. And can (most times) be evil, especially when trying to do a simple update and suddenly something else gets changed because of a callback.Callbacks should be simple, and should not be intrusive. When you find yourself calling model.save(validate: false) to avoid a callback, it is time you look into refactoring.Some less evil examples are:Sending email when creating a user (still a pretty evil)Adding timestamp when a boolean changed.Generating a user token on create.
Lesser Model Callbacks — Refactoring Rails the Clean Way #ruby #rubydeveloper #rubyonrails #callbacks — refactoring https://rubyonrails.ba/single/lesser-model-callbacks-refactoring-rails-the-clean-way

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles