我应该如何在after_create回调中编写多个条件 [英] How should I write multiple condition in after_create callbacks

查看:76
本文介绍了我应该如何在after_create回调中编写多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模型中有一个在创建后会调用的方法

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?

推荐答案

对于较短的可读版本,您也可以这样做

You can also do this for a shorter readable version

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

P.S:->是编写lambda的简写.

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

这篇关于我应该如何在after_create回调中编写多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆