I have a method in a service object that composes operations that should be wrapped in a transaction. Some of these operations are also wrapped in transactions. For example:
Another easier approach, you can raise an CustomError < StandardError. Unlike ActiveRecord::Rollback, Error will bubble up through parent transactions. You can handle it wherever required. All other inner transactions will be rolled back.
Try the below template.
ActiveRecord::Base.transacton do
ActiveRecord::Base.transacton do
raise StandardError.new
end
end