Displaying 2 results from an estimated 2 matches for "created_by_user_id".
2006 Jan 16
16
acts_as_authenticated current_user in a model?
...*******************************
Here is what I am trying to do:
**********************************************************
class Setting < ActiveRecord::Base
before_create :created_by_user # create only
before_save :updated_by_user # both, create and update
def created_by_user
self.created_by_user_id = current_user.id
self.created_by_user_login = current_user.login
end
def updated_by_user
self.updated_by_user_id = current_user.id
self.updated_by_user_login = current_user.login
end
end
**********************************************************
But it gives me this error:
***...
2006 Jan 03
2
help me understand association attributes
...st 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...