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

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

Asked on January 11, 2019 in Ruby on Rails.
Add Comment


  • 2 Answer(s)

    After_create only works once – just after the record is first created.

    After_save works every time you save the object – even  just updating it many years later.

    So if you want to do this email operation only just the once and then never again then use after_create.

    Answered on January 11, 2019.
    Add Comment

    Note:

    After_create()

    Is called after Base.save on new objects that haven‘t been saved yet (no record exists).

    After_save()

    Is called after Base.save regardless of whether it‘s a create or update save.

    Answered on January 11, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.