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

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
@[email protected]
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
But it’s missing the reason.

Thanks,
martin

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
@[email protected]
doesn’t work.

Because activerecord attributes aren’t stored as instance variables.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs