# After\_save -- stack level too deep

**URL:** <https://www.ruby-forum.com/t/after-save-stack-level-too-deep/158030>\
**Category:** Rails\
**Created:** [January 18, 2009, 5:34am UTC](https://www.ruby-forum.com/t/after-save-stack-level-too-deep/158030 "2009-01-18T05:34:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neal\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@Neal\_L](https://www.ruby-forum.com/u/Neal_L)\
**Post date:** [January 18, 2009, 5:34am UTC](https://www.ruby-forum.com/t/after-save-stack-level-too-deep/158030/1 "2009-01-18T05:34:54Z")

</div>

Hi all,

I’m running into a brick wall trying to figure out my problem here. I  
have a model that has a boolean property called “paid”. I’d like to  
add the following to my model:

def after\_save  
self.amount == self.splits.sum(:amount) ? self.update\_attribute  
(:paid, true) : self.update\_attribute(:paid, false)  
end

The problem is, when I do this I get an error that my stack level is  
too deep. If I throw this in with one of the model’s validators it  
works just fine, but that’s not the right way to do this…

I don’t see how I’m recursing here, so any help would be appreciated!

Thanks!

---

<div class="post-metadata">

**Author:** ![Neal\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@Neal\_L](https://www.ruby-forum.com/u/Neal_L)\
**Post date:** [January 18, 2009, 10:38am UTC](https://www.ruby-forum.com/t/after-save-stack-level-too-deep/158030/2 "2009-01-18T10:38:59Z")

</div>

update\_attribute saves the updated record, so after\_save will be called  
again, hence the recursion.  
Colin

---

<div class="post-metadata">

**Author:** ![Neal\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@Neal\_L](https://www.ruby-forum.com/u/Neal_L)\
**Post date:** [January 18, 2009, 7:55am UTC](https://www.ruby-forum.com/t/after-save-stack-level-too-deep/158030/3 "2009-01-18T07:55:46Z")

</div>

You should update by sql in after\_save.

On Sun, Jan 18, 2009 at 12:34 PM, Neal L [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end

–  
TWRUG Blog:  
[http://blog.rubyonrails.org.tw](http://blog.rubyonrails.org.tw)

CFC on Rails:

> **[CFC on Rails](http://zusocfc.blogspot.com)**
>
> 火車請別撞我

Only two surfaces of a box:  
[http://blog.pixnet.net/zusocfc](http://blog.pixnet.net/zusocfc)
