# Before\_save and create

**URL:** <https://www.ruby-forum.com/t/before-save-and-create/135860>\
**Category:** Rails\
**Created:** [April 25, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/before-save-and-create/135860 "2008-04-25T18:42:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![raam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@raam](https://www.ruby-forum.com/u/raam)\
**Post date:** [April 25, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/before-save-and-create/135860/1 "2008-04-25T18:42:16Z")

</div>

Hi,

I have a strange problem with before\_save and create.

In my controller I have:

self.current\_cart = Cart.create(:user\_id =\> current\_user.id, :status =\>  
CURRENT\_CART)  
self.current\_cart.update\_attributes({:order\_num =\> self.current\_cart.id  
+  
seed\_num })

This works well until I add a before\_save in the model:

def before\_save  
self.is\_cached = false  
end

Now I get an error in the update\_attributes call that  
self.current\_cart.idis nil. Any idea why this could happen?

Thanks,

Ram

---

<div class="post-metadata">

**Author:** ![raam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@raam](https://www.ruby-forum.com/u/raam)\
**Post date:** [April 25, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/before-save-and-create/135860/2 "2008-04-25T18:45:12Z")

</div>

On 25 Apr 2008, at 17:41, Ram R. wrote:

> 

if a before\_save callback returns false then the save is cancelled

Fred
