I want to update an attribute on an object, but keep the attribute updated_at
(DateTime type) unchanged.
This doesn't seem to work, the updated_at
gets current date/time:
p = Post.first
p.update(updated_at: p.updated_at, published: true)
I want to update an attribute on an object, but keep the attribute updated_at
(DateTime type) unchanged.
This doesn't seem to work, the updated_at
gets current date/time:
p = Post.first
p.update(updated_at: p.updated_at, published: true)
Just use update_all method, it does not touch updated_at field http://apidock.com/rails/ActiveRecord/Base/update_all/class
Asked and answered here: Is there a way to avoid automatically updating Rails timestamp fields?
But the short answer is to use
update_columns
.i.e. user.update_columns(last_request_at: Time.current)
More info here: http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_column