# Callback Problem: Why to use self.var= instead of @var=

**URL:** <https://www.ruby-forum.com/t/callback-problem-why-to-use-self-var-instead-of-var/135088>\
**Category:** Rails\
**Created:** [April 17, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/callback-problem-why-to-use-self-var-instead-of-var/135088 "2008-04-17T19:40:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![html-kurs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ea5d25/32.png) [@html-kurs](https://www.ruby-forum.com/u/html-kurs)\
**Post date:** [April 17, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/callback-problem-why-to-use-self-var-instead-of-var/135088/1 "2008-04-17T19:40:24Z")

</div>

Hi,

I’ve defined the following model:

class Eintrag \< ActiveRecord::Base  
before\_validation :vali

protected  
def vali

# self.feld1.reverse!

```
self.feld2 = self.feld1

```

end  
end

Now I’m wondering why I have to write  
self.feld2=self.feld1  
and why  
@feld2=@feld1  
doesn’t work.

I’ve found the thread  
[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/3405e38a2f34e896/7cfa3cb86d87d034?lnk=gst&q=callback+self+instance#7cfa3cb86d87d034](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/3405e38a2f34e896/7cfa3cb86d87d034?lnk=gst&q=callback+self+instance#7cfa3cb86d87d034)  
But it’s missing the reason.

Thanks,  
martin

---

<div class="post-metadata">

**Author:** ![html-kurs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ea5d25/32.png) [@html-kurs](https://www.ruby-forum.com/u/html-kurs)\
**Post date:** [April 17, 2008, 8:12pm UTC](https://www.ruby-forum.com/t/callback-problem-why-to-use-self-var-instead-of-var/135088/2 "2008-04-17T20:12:42Z")

</div>

On 17 Apr 2008, at 18:39, Martin wrote:

> # self.feld1.reverse!
> 
> self.feld2 = self.feld1  
> end  
> end
> 
> Now I’m wondering why I have to write  
> self.feld2=self.feld1  
> and why  
> @feld2=@feld1  
> doesn’t work.

Because activerecord attributes aren’t stored as instance variables.

Fred
