Rails after_validation or before_save

I dont think i used after_validation ever as before_save(or similar callbacks like before_create or update) is the one which fits. Usually the flow is

Screen Shot 2018-08-03 at 1.45.57 PM

before_save seems to be the last step in the process and by the time it reaches there the record is valid. Like you wanted it to happen every time when validation is successful.

after_validation is called irrespective of the validation failed or not. I cant think of a scenario where you want to use it.

We cannot substitute after_validation for before_save as we can not guarantee that the record is always going to be valid.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.