Ruby on rails, Change column value on update of other column value
问题 I have two columns related to each other in a Rails model: Article.body Article.body_updated_on I want to change the Article.body_updated_on to Time.now , every time Article.body is updated. If any other fields updated nothing needs to be happen. 回答1: Just add before save callback to your Article model class Article < ActiveRecord:Base before_save :update_body_modified private # <--- at bottom of model def update_body_modified self.body_updated_on = Time.now if body_changed? end end 回答2: You