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 #rails #rubyonrails #bosnia #programming #tutorials #rubydeveloper #railsdeveloper

Nezir Zahirovic

Freelance software developer Ruby On Rails (4 years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles