Common onesupdate(attributes)update!(attributes)update_allupdate_attributesupdate_attribute update_column and update_columnsList of Update MethodsRails 3Rails 4Source
Common ones
update(attributes)
- The most common one
- Trigger everything like validation/callbacks and etc
# Updating one record:
Person.update(15, :user_name => 'Samuel', :group => 'expert')
# Updating multiple records:
people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }
Person.update(people.keys, people.values)update!(attributes)
- Calls
save!internally, so it raises exception if errored
- Others are the same as
update
update_all
- Does not trigger callbacks or validations
User.update_all max_login_attempts: 3, must_change_password: trueupdate_attributes
update_attributestriggers validations
- Rails 6 deprecated
update_attributesso just useupdate
update_attribute
update_attributedoes not trigger validation
update_column and update_columns
- Avoid using these because not all hooks are triggered