---------- Forwarded message ----------
From: Charlie Bowman
<charlesmbowman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Aug 31, 2006 7:48 PM
Subject: adding a method to an ActiveRecord Object
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
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
On 8/31/06, Charlie Bowman
<charlesmbowman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
>
> ---------- Forwarded message ----------
> From: Charlie Bowman
<charlesmbowman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Date: Aug 31, 2006 7:48 PM
> Subject: adding a method to an ActiveRecord Object
> To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>
> 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
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060831/992fb55e/attachment.html