When we usually modify any specific column/field in our model, Active-record will check whether the corresponding value is new or not.
If it is new then only it will create a DB query and update that value with current timestamp in updated_at column, if there is no change in existing value means it will only fire commit query only. There wont be any change in updated_at column.
So if we want modify the timestamp of updated_at field without updating any field means, we can follow any of below two methods:
Method 1:
user.update_attributes(:name => “same old name”, :updated_at => Time.now)
Method 2:
user.touch
Both of above two methods will modify updated_at value with current timestamps even if there is any change in other fields or not.
Thanks!
Comment by David — July 25, 2017 @ 6:06 am