Using ActiveRecord, is there a way to get the old values of a record during after_update

后端 未结 10 1052
耶瑟儿~
耶瑟儿~ 2021-01-30 08:20

Setup using a simple example: I\'ve got 1 table (Totals) that holds the sum of the amount column of each record in a second table (

10条回答
  •  深忆病人
    2021-01-30 08:45

    If you want to get value of particular field after update you can use field_before_last_save method.

    Example:
    
    u = User.last
    u.update(name: "abc")
    
    u.name_before_last_save will give you old value (before update value)
    

提交回复
热议问题