method

update_attribute

update_attribute(name, value)
public

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 aren’t subjected to validation checks. Hence, attributes can be updated even if the full object isn’t valid.

4Notes

Validations

Ariejan · Aug 11, 20088 thanks

+update_attribute+ will not perform validations checks when the Validation module is included.

If you want to perform validations when updating, use +update_attributes+ instead.

This method will still rewrite all the values of the table

railsmonk · Feb 3, 20094 thanks

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.

Update statement won't include all attributes with ActiveRecord::Dirty

TheDeadSerious · Oct 22, 20094 thanks

With the addition of ActiveRecord::Dirty, the update statement will only feature changed columns, as opposed to the comment of railsmonk below.

callbacks

rogerdpack · Aug 19, 2014

As a note, AFAICT, this skips "validations" but does still run all callbacks still [like after_save, etc.] So if you're looking for something that just updates see here: http://stackoverflow.com/a/7243777/32453