# @new\_record\_before\_save

**URL:** <https://www.ruby-forum.com/t/new-record-before-save/167808>\
**Category:** Rails\
**Created:** [May 12, 2009, 8:27pm UTC](https://www.ruby-forum.com/t/new-record-before-save/167808 "2009-05-12T20:27:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 12, 2009, 8:27pm UTC](https://www.ruby-forum.com/t/new-record-before-save/167808/1 "2009-05-12T20:27:21Z")

</div>

Is there an easy way to access the ActiveRecord  
@new\_record\_before\_save attribute?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 12, 2009, 8:38pm UTC](https://www.ruby-forum.com/t/new-record-before-save/167808/2 "2009-05-12T20:38:33Z")

</div>

> Is there an easy way to access the ActiveRecord  
> @new\_record\_before\_save attribute?

Maybe…

> > u = User.new  
> > u.new\_record?  
> > =\> true

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 12, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/new-record-before-save/167808/3 "2009-05-12T21:47:17Z")

</div>

On May 12, 2009, at 2:26 PM, TomRossi7 wrote:

> Is there an easy way to access the ActiveRecord  
> @new\_record\_before\_save attribute?
> 
> Thanks,  
> Tom

Well, it depends on what you mean by easy.

model.instance\_variable\_get(‘@new\_record\_before\_save’) will work

If you’re using an older ActiveRecord and you are trying to tell the  
difference between a find\_or\_create\_by\_…, You can “rely” on the  
deprecated model.new\_record?.nil? to know that it was a find  
(model.new\_record? == false means it was actually a create)

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
