# How extend model attributes?

**URL:** <https://www.ruby-forum.com/t/how-extend-model-attributes/118993>\
**Category:** Rails\
**Created:** [November 2, 2007, 12:19am UTC](https://www.ruby-forum.com/t/how-extend-model-attributes/118993 "2007-11-02T00:19:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 2, 2007, 12:19am UTC](https://www.ruby-forum.com/t/how-extend-model-attributes/118993/1 "2007-11-02T00:19:12Z")

</div>

How do I add arbitrary attributes to an AR model?

It would appear that simply adding instance vars with accessors to an  
AR model doesn’t actually work the same way as a regular class. Quite  
confused by that.

The attributes derived by reflection is fine, but I have several  
other attributes that will not come from the data table. Most are  
state vars or behavior modification vars derived from config settings  
or application logic. These + the data table combine to make up the  
whole model.

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 2, 2007, 1:09am UTC](https://www.ruby-forum.com/t/how-extend-model-attributes/118993/2 "2007-11-02T01:09:26Z")

</div>

On Nov 1, 2007, at 4:18 PM, Greg W. wrote:

> whole model.  
> Hmm, well after untold permutations, I finally struck upon the  
> combination that works.

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 2, 2007, 4:40am UTC](https://www.ruby-forum.com/t/how-extend-model-attributes/118993/3 "2007-11-02T04:40:24Z")

</div>

attr\_accessor :name

Basically sets up a getter setter for the attribute so you can do  
self.name= and self.name.
