Skip to content

Instantly share code, notes, and snippets.

@moserrya
Last active August 29, 2015 14:09
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 moserrya/c276d5d8a93f8a54bfee to your computer and use it in GitHub Desktop.
Save moserrya/c276d5d8a93f8a54bfee to your computer and use it in GitHub Desktop.
item = Item.find 328
item.transaction do
item.feelings.create!(size: 'huge')
item.update_attributes!(state: "sold")
end
# item.update_attributes! fails a validation, which we rescue. new feeling that we created is rightly rolled back
item.save #saves the feelings record that was rolled back as part of our transaction!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment