Skip to content

Instantly share code, notes, and snippets.

@krbullock
Forked from texel/gist:191269
Created September 22, 2009 18:18
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 krbullock/191297 to your computer and use it in GitHub Desktop.
Save krbullock/191297 to your computer and use it in GitHub Desktop.
class FooBarTransactionFailed < ActiveRecord::RecordInvalid
def initialize(foo, bar)
@foo, @bar = foo, bar
end
end
begin
transaction do
foo = FooClass.create(:blah => 'blah')
bar = BarClass.create(:bleh => 'bleh')
raise FooBarTransactionFailed.new(foo, bar) if (foo.new_record? && bar.new_record?)
return foo, bar, 'success'
end
rescue FooBarTransactionFailed => e
return e.foo, e.bar, 'error'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment