Lesser Model Callbacks — Refactoring Rails the Clean Way
06-Dec-2018 1869
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 #Lesser #Model #Callbacks — Refactoring #Rails #Clean #callbacks — refactoring https://rubyonrails.ba/link/lesser-model-callbacks-refactoring-rails-the-clean-way