Rails after_save 不能使用 previous_changes
项目中希望Model A
某个字段(例如为attr)保存成功后touch一下相关联的Mobel B
,所以尝试在Model A
中使用
after_save :touch_method, if: :attr_is_changed?
def touch_method
......
end
def attr_is_changed?
previous_changes.include?(:attr)
end
查看网上一些资料发现,after_save后,previous_changes就会被置空了,所以attr_is_changed?
一直都是返回false的。
请问大家有什么方法可以解决这个问题?