A
A
Anton Misyagin2020-02-07 14:57:04
Ruby on Rails
Anton Misyagin, 2020-02-07 14:57:04

How do you know if a Rails transaction is open?

def some_usefull_regular_action
raise 'method must call with transaction. Rollback' unless transaction.open?
operation A
operation B
end

Controller
def my_action
ActiveRecord.transaction do some_usefull_regular_action
()
operation C
end
end Ps I'm writing from my phone.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Misyagin, 2020-02-09
@sunnmas

def some_usefull_regular_action
  raise 'method must call with transaction. Rollback' unless ActiveRecord::Base.connection.transaction_open?
  operation A
  operation B
end

controller
def my_action
  ActiveRecord::Base.connection.transaction do
    some_usefull_regular_action()
    operation C
  end
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question