In my controller, I have code that looks like the following:
@mymodel.transaction do
for a in arr
@mymodel.some_method(a)
end
end
in @mymodel#some_method I could throw an ActiveRecord::Rollback
exception which in the db does what it needs to do, however I then simply get an HTTP 500 and no way to catch the exception to let the user know in an elegant way what went wrong.
I've tried wrapping @mymodel.transaction do in a begin/rescue block, but that won't do it either. What's the best way to catch the exception so I can present the proper view to the user?