Skip to content

Instantly share code, notes, and snippets.

@jdar
Created September 26, 2009 20:29
Show Gist options
  • Save jdar/194409 to your computer and use it in GitHub Desktop.
Save jdar/194409 to your computer and use it in GitHub Desktop.
# in the console ...
def try_to_fail(p)
begin
MyModel.transaction do
p.name = "Eustace"
p.save
5+5
raise Exception
end
rescue Exception
puts "not saved"
end
end
>> p = MyModel.new
>> try_to_fail(p)
not saved
=> nil
>> p
=> #<MyModel id: 1784, name: "Eustace", number: nil, type: nil>
def try_to_fail_without_begin_block(p)
Pin.transaction do
p.name = "harold"
p.save
5+5
raise Exception
end
end
>> p = Pin.new
>> try_to_fail_without_begin_block(p)
=> Exception raised ... with traceback
>> p
=> #<MyModel id: 1784, name: "Eustace", number: nil, type: nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment