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

后端 未结 10 1053
耶瑟儿~
耶瑟儿~ 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:54

    To get all changed fields, with their old and new values respectively:

    person = Person.create!(:name => 'Bill')
    person.name = 'Bob'
    person.save
    person.changes        # => {"name" => ["Bill", "Bob"]}
    

提交回复
热议问题