ActiveRecord#update_attribute saves the entire record
Let’s say that you need to update one attribute in an activerecord:
my_record.update_attribute("some_column", "some_value")
you might expect that only “some_column” will change, but that’s not what happens. When you call update_attribute the entire row (object) is saved, and validations are bypassed!
This might surprise you (it surprised me), especially the no-validation part. This means that it’s possible to corrupt a record in the database, by setting a column to an invalid value (for which there’s a validation). Then call update_attribute on a different attribute, and bam, the invalid field is saved along with the attribute being updated.
The proper way to update attributes while still invoking the record validation is to call update_attributes (notice the “s”) and pass it a hash of attributes to update:
my_record.update_attributes("some_column" => "some_value")
This will still save the entire record, but at least validations will run.
(more about ActiveRecord here)