如何获得在Rails的一个属性的初始值 [英] How to get the original value of an attribute in Rails
本文介绍了如何获得在Rails的一个属性的初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法来获得原始值的ActiveRecord的属性(=被从数据库加载值)?
is there a way to get the original value that an ActiveRecord attribute (=the value that was loaded from the database)?
我想是这样的以观察员
before_save object
do_something_with object.original_name
end
的任务是从哈希表中删除该对象(事实上,它移动到在表中的另一个关键)在更新
The task is to remove the object from a hash table (in fact, move it to another key in the table) upon updating.
推荐答案
追加 _was
你的属性会给你previous值。
Appending _was
to your attribute will give you the previous value.
这篇关于如何获得在Rails的一个属性的初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文