ruby-on-rails 如何在after_create回调中编写多个条件

svmlkihl  于 2023-02-10  发布在  Ruby
关注(0)|答案(2)|浏览(110)

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

after_create :generate_insurer_recovery_invoice, if: :insurance_recovery_batch?

我应该如何在这个回调中编写另一个条件?

n6lpvg4x

n6lpvg4x1#

您也可以为较短的可读版本执行此操作

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

另外,->lambda的简写形式。

yyyllmsg

yyyllmsg2#

我想这对你可能有用
你可以从下面的帖子中获得类似的东西
Multiple conditions on callbacks

after_save :update_offices_people_count

private

def update_offices_people_count
  if office_id_changed? || trashed_changed?  
    ...
  end
end

相关问题