Before_save, before_validation: on =>: save

I wanted to add a hook to before_save. Validation occurs before calling "before_save", so I moved it to before_validation: on =>: save.

Now the problem is when I do @ object.save_without_validation (sometimes I had to use this). my hook before_validation is not called.

Am I missing something or is there a more reliable way to add to the hook that works for both cases?

+5
source share
1 answer

Hi, when you save the object, you have the following callbacks

* before_validation
* after_validation
* before_save
* after_save
* before_create
* around_create
* after_create

try to put your code inside after_validation

+10
source

All Articles