Skip to content

Instantly share code, notes, and snippets.

@cybersamx
Last active August 29, 2015 14:05
Show Gist options
  • Save cybersamx/e993874a9932f5f6fe03 to your computer and use it in GitHub Desktop.
Save cybersamx/e993874a9932f5f6fe03 to your computer and use it in GitHub Desktop.
Update Rails ActiveRecord object without triggering validation and updating updated_at
object = MyModel.create(name: 'Sam')
# update_attribute bypass validation but will touch update_at
object.update_attribute(:name, 'Yo')
object.name == 'Yo' # true
object.name_changed? # false
# update_column bypass validation but will not touch update_at
object.update_column(:name, 'Yo')
object.name == 'Yo' # true
object.name_changed? # false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment