DEV Community

Discussion on: ActiveRecord Callbacks you need to know

Collapse
bizzibody profile image
Ian bradbury

Are there any times when you would not recommend using call backs?

Collapse
nkemjiks profile image
Mbonu Blessing Author

Sure. That would be in cases were you can clean up your data in the controller or use database default values. For instance, if I have an article model with a boolean datatype for the published value, and I am using a before_validation to set the default value of false if its nil, that is a wrong use of callbacks even if it works. You could have easily set a default value when creating that database column since we know it's always going to be false until the creator of the article decides to publish it.