What is the difference between `after_create` and `after_save` and when to use which?

后端 未结 3 463
独厮守ぢ
独厮守ぢ 2020-12-04 15:19

Are after_create and after_save the same as per functionality?

I want to do an operation with the email of a user after its account creatio

3条回答
  •  渐次进展
    2020-12-04 15:40

    after_save()
    

    Works fine when you have to save models that do not save very often. For this particular example of changing records frequently it would be advisable to use

     after_commit()
    

    make sure that the model is saved in the database before the action is executed after_commit :calculate_credit_score

    def calculate_credit_score
         #Call a Cron job
    end
    

提交回复
热议问题