I have a model with a belongs_to association. The first model is called Thing and the associated model is User. I'm attempting to assign the user to the thing. To accomplish this I used a before_save method, like this: class Thing < ActiveRecord::Base belongs_to :created_by, :class_name => "User", :foreign_key => "created_by_user_id" def before_create self.created_by = get_user() end I had trouble getting the assignment to work. I initially tried simply created_by = get_user() (no 'self') I don't know why 'self' made a difference in this case. Can anyone explain this to me? Thank you. -Kelly
on 2006-01-03 02:56
on 2006-01-03 04:36
Kelly Dwight Felkins wrote: > def before_create > self.created_by = get_user() > end > > I had trouble getting the assignment to work. I initially tried simply > > created_by = get_user() > > (no 'self') I don't know why 'self' made a difference in this case. Can > anyone explain this to me? Have a read of this: http://groups.google.com/group/comp.lang.ruby/brow... -- We develop, watch us RoR, in numbers too big to ignore.
on 2006-01-03 07:49
Thank you. -Kelly