在Rails 4中after_save方法中previous_changes为空。
解决方法:
用changed_attributes或@previously_changed代替。
ActiveModel::Dirty 274行:
def changes_applied # :doc:
@previously_changed = changes
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end
因为在实例方法中after_save还没有保存到数据库中。
而previous_changes在记录保存到数据库中生效。