How to update a single attribute without touching the updated_at attribute?

As an alternative to update_attribute, In Rails 3.1+ you can use update_column.

update_attribute skips validations, but will touch updated_at and execute callbacks.

update_column skips validations, does not touch updated_at, and does not execute callbacks.

Thus, update_column is a great choice if you don’t want to affect updated_at and don’t need callbacks.

See http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html for more information.

Also note that update_column will update the value of the attribute in the in-memory model and it won’t be marked as dirty. For example:

p = Person.new(:name => "Nathan")
p.save
p.update_column(:name, "Andrew")
p.name == "Andrew" # True
p.name_changed? # False

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)