Fwd: adding a method to an ActiveRecord Object

---------- Forwarded message ----------
From: Charlie B. [email protected]
Date: Aug 31, 2006 7:48 PM
Subject: adding a method to an ActiveRecord Object
To: [email protected]

I’ve already pulled my object from the database. Now I want to add a
method. What I’m doing is adding the username to the activerecord
object so
I’ll have the name and user_id. How can I do this. The code below
fails in
the view. It appears it’s overwriting the rest of my object

def self.find_with_author(id)
@article = Article.find(id)
logger.error(“user id = #{@article.user_id}”)
@user = User.find(:first, :conditions => [“id = ?”,@article.user_id
])
@article[‘author’] = @user.login
end

I figured it out. I forgot to explicitly return the correct value. Is
there a better way of doing this. it feels a little wrong to add items
directly to the hash.

def self.find_with_author(id)
@article = Article.find(id)
logger.error(“user id = #{@article.user_id}”)
@user = User.find(:first, :conditions => [“id =
?”,@article.user_id])
@article[‘author’] = @user.login
@article
end