views:

32

answers:

2

I have a Class A that when it is instantiated and saved for the first time or modified it will create an instance of Class B and save it also

I want them to be in the same transaction and I want it to be handled in the Model not a controller.

I know how to do this in a conteoller with the ‘transaction do’ block but how do I do it in the model?

Thanks

A: 

use models callbacks such as before_save or before_create etc

http://apidock.com/rails/ActiveRecord/Callbacks

fl00r
A: 

Do it in an after_save callback, which is in the same transaction as the original save. See the Rails guides.

Jonathan Julian
Cool, I just did not realize it was the same transaction. Thanks!
Will