ruby on rails 3 - Keeping the previous value of an attribute -
i have following situation: if name attribute of student object changes, want keep old value , save table.
so, if have student object name attribute 'john 1', after student.update_attributes(:name => 'john 2') want able capture old name value 'john 1' in before_update callback hook, instance. what's best way ? in advance.
in before_update hook, can access special _was methods previous value of each field
before_update new_name = self.name # 'john 2' old_name = self.name_was # 'john 1' end
Comments
Post a Comment