Rails 2.1 keeps track of the changes you make to a model's attributes. It also allows you to see what the previous value was. But watch out for the gotcha! See this episode for details.
# config/initializers/active_record_settings.rb
ActiveRecord::Base.partial_updates = true
# change tracking methods
p.changed?
p.changed
p.changes
p.name_changed?
p.name_was
p.name_change
p.name_will_change!
Rails变更追踪
Rails 2.1 版本中引入了变更追踪功能,能够记录模型属性的变化并允许开发者查看之前的值。需要注意的是,在使用该功能时要小心陷阱,并正确配置 ActiveRecord 的部分更新设置。
884

被折叠的 条评论
为什么被折叠?



