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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -