Skip to content

Instantly share code, notes, and snippets.

@pragtobgists
Created December 11, 2017 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pragtobgists/d680bbf6fe7aa2ec96d488ce73c7016b to your computer and use it in GitHub Desktop.
Save pragtobgists/d680bbf6fe7aa2ec96d488ce73c7016b to your computer and use it in GitHub Desktop.
A not so coll rollback user
class User < ApplicationRecord
attr_accessor :rollback
after_save :potentially_rollback
def potentially_rollback
raise ActiveRecord::Rollback if rollback
end
end
User.transaction do
User.create(name: 'Kotori')
User.create(name: "someone", rollback: true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment