# ActiveRecord: Attribute Setter for belongs\_to relation attr

**URL:** <https://www.ruby-forum.com/t/activerecord-attribute-setter-for-belongs-to-relation-attr/107819>\
**Category:** Rails\
**Created:** [June 26, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/activerecord-attribute-setter-for-belongs-to-relation-attr/107819 "2007-06-26T15:13:32Z")\
**Posts on this page:** 2\
**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:** [June 26, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/activerecord-attribute-setter-for-belongs-to-relation-attr/107819/1 "2007-06-26T15:13:32Z")

</div>

Hi,

I m trying to link into the process of setting an belongs\_to attribute  
in my model. Unfortunetly, it does not seem to be as easy as for  
“normal” attributes.

I ve tried the following:  
class Treatment \< ActiveRecord::Base  
belongs\_to :drug

def drug=(new\_value)  
'my stuff  
super new\_value  
end

However, that does not work. Ive also tried self[:drug] = new\_value…  
However, that is also not working.

Any ideas?

Thanks a lot in advance.

–  
Volker

---

<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:** [June 26, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/activerecord-attribute-setter-for-belongs-to-relation-attr/107819/2 "2007-06-26T17:55:54Z")

</div>

removed\_email\_address@domain.invalid wrote:

> ```
> super new_value
> 
> ```
> 
> end
> 
> However, that does not work. Ive also tried self[:drug] = new\_value…  
> However, that is also not working.

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/4fe057494c6e23e8](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/4fe057494c6e23e8)

–  
We develop, watch us RoR, in numbers too big to ignore.
