Update Records

This guide shows you how to update existing records in the database.

Update with save

Change attributes and save:

user = User.find(1)
if user
  user.name = "Updated Name"
  user.save
  puts "Updated!"
end

Update with save!

Raise on failure:

user = User.find!(1)
user.name = "Updated Name"
user.save!  # Raises if validation fails

Update with update!

Update multiple attributes at once:

Bulk Update

Update multiple records matching a condition:

Increment a Value

Conditional Update

Update Only Changed Fields

CQL tracks changes automatically:

Update with Validation

Validations run on update:

Update Timestamps

If your model has timestamps, updated_at is set automatically:

Update Without Callbacks

To skip callbacks (use carefully):

Verify Update

Last updated

Was this helpful?