Created
December 11, 2017 21:52
-
-
Save pragtobgists/d680bbf6fe7aa2ec96d488ce73c7016b to your computer and use it in GitHub Desktop.
A not so coll rollback user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
attr_accessor :rollback | |
after_save :potentially_rollback | |
def potentially_rollback | |
raise ActiveRecord::Rollback if rollback | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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