Search code examples
ruby-on-railsmodelcallback

How should I write multiple condition in after_create callbacks


I have a method in model that calls after create

after_create :generate_insurer_recovery_invoice, if: :insurance_recovery_batch?

How should I write another condition within this callback?


Solution

  • You can also do this for a shorter readable version

    after_save :update_offices_people_count, if: -> {office_id_changed? || trashed_changed?}
    

    P.S: -> is a shorthand version of writing lambda.