activerecord - How to get current value of attribute before saving new one in AR? -
i have model such attributes:
some_number
some_string
i want put value in some_string
depending on current value of some_number
, new value of some_number
on updating.
example:
current some_number
4
new (updated) value of some_number
5
i want put 4+5
string some_string
before some_number
overwritten.
how can worked?
if need modify attribute depending on other attribute value on update event i'd that:
class thing < activerecord::base before_update :modify_some_string protected def modify_some_string # actions self.some_string , self.some_number # , self.some_string_was , self.some_number_was end end
Comments
Post a Comment