# After\_initialize isn't being called on AR object

**URL:** <https://www.ruby-forum.com/t/after-initialize-isnt-being-called-on-ar-object/145786>\
**Category:** Rails\
**Created:** [August 13, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/after-initialize-isnt-being-called-on-ar-object/145786 "2008-08-13T22:53:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [August 13, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/after-initialize-isnt-being-called-on-ar-object/145786/1 "2008-08-13T22:53:48Z")

</div>

All,

I have the following AR object:

class UploadedFile \< ActiveRecord::Base

protected  
def after\_initialize  
self.path = ‘abc’  
end  
end

When I call UploadedFile.new and pass it a value for the “name”  
attribute, I don’t see the path attribute get a value like I expect.

See (from script/console):

> > uf = UploadedFile.new(:name =\> “xyz”)  
> > =\> #\<UploadedFile id: nil, name: “xyz”, path: nil, created\_at: nil,  
> > updated\_at: nil\>

AFAIK, after\_initialize is ok to use in Rails 2.1.

What am I doing wrong here?

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [August 13, 2008, 11:16pm UTC](https://www.ruby-forum.com/t/after-initialize-isnt-being-called-on-ar-object/145786/2 "2008-08-13T23:16:19Z")

</div>

Never mind.
