请各位看看我这个简单的范例代码:
rails g scaffold accounts total:integer
rake db:migrate
rails c
> acc = Account.new
> acc_id = Account.first.id
> acc1 = Account.find(acc_id)
> acc2 = Account.find(acc_id)
> acc1 == acc2 # true
> acc1.object_id == acc2.object_id # false
Account model class 有个 add_total 的方法
def add_total(number)
new_total = total + number
update_attribute(:total, new_total)
acc1.add_total(10)
acc2.add_total(10)
期望 Account.first.total 结果为 20 但却是 10