Masatoshi Nishiguchi

Updating an object to database in Rails

This is my memo on Updating an object to database in Rails.

# Applies the validations.
user.update(name: "The Dude", email: "dude@abides.org")
user.update_attributes(name: "The Dude", email: "dude@abides.org")

# Bypasses the validation.
# For updating a single attribute.
user.update_attribute(:name, "The Dude")
user.update_column(:name, "The Dude")

# Bypasses the validation.
# For updating a single attributes.
user.update_columns(activated: true, activated_at: Time.zone.now)

Reference