Updates a single attribute and saves the record. This is especially useful for boolean flags on existing records. Note: This method is overwritten by the Validation module that’ll make sure that updates made with this method doesn’t get subjected to validation checks. Hence, attributes can be updated even if the full object isn’t valid.
# File activerecord/lib/active_record/base.rb, line 1431 def update_attribute(name, value) send(name.to_s + '=', value) save end
Even if you update only a small boolean flag on your record, update_attribute will generate an UPDATE statement that will include all the fields of the record, including huge BLOB and TEXT columns. Take this in account.
Despite the name and description, it will actually update any changed fields on the model rather than just the desired attribute.
def update_attribute(name, value) send(name.to_s + '=', value) save(false) end
See? Use update_all and pass in the model ID as a condition, instead.