# Where to put the transaction?

**URL:** <https://www.ruby-forum.com/t/where-to-put-the-transaction/141345>\
**Category:** Rails\
**Created:** [June 24, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/where-to-put-the-transaction/141345 "2008-06-24T21:48:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/67e7ee/32.png) [@kap](https://www.ruby-forum.com/u/kap)\
**Post date:** [June 24, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/where-to-put-the-transaction/141345/1 "2008-06-24T21:48:56Z")

</div>

Hi, I’m rewriting some really old code these days and I’m trying to  
adhere to the “fat model, skinny controller” approach.

I’m wondering how much to actually stuff into the model, and if  
there’s some rule of thumb. For example, I could do this in a  
controller:

def controller\_action  
MyModel.transaction do  
instance.do\_stuff  
instance.associated\_thing.other\_stuff  
instance.save!  
end  
end

Or, I could put it all on the model instance:

def do\_stuff  
MyModel.transaction do  
some\_methods\_here  
associated\_thing.other\_stuff  
save!  
end  
end

Any tips on what’s preferable and when/why?

Thanks.

---

<div class="post-metadata">

**Author:** ![kap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/67e7ee/32.png) [@kap](https://www.ruby-forum.com/u/kap)\
**Post date:** [June 25, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/where-to-put-the-transaction/141345/2 "2008-06-25T18:38:43Z")

</div>

Hello,

This is just a “me too” … I am just now comfortable enough with  
rails to be able to accomplish a task both of those ways, and I have a  
tough time figuring out when I should choose on or the other. The  
Railscasts from [http://railscasts.com/](http://railscasts.com/) are quite helpful, that’s how I  
have been figuring it out.

Dustin
