# Comments with name

**URL:** <https://www.ruby-forum.com/t/comments-with-name/131129>\
**Category:** Rails\
**Created:** [March 6, 2008, 9:43am UTC](https://www.ruby-forum.com/t/comments-with-name/131129 "2008-03-06T09:43:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [March 6, 2008, 9:43am UTC](https://www.ruby-forum.com/t/comments-with-name/131129/1 "2008-03-06T09:43:33Z")

</div>

Hi, so I am trying to display the author’s name of comments. I am  
able to display the comments by iterating through the hash

@comments = PhotoComment.find(:all, :conditions =\> { :photo\_id =\>  
params[:photo\_id] }),

but I want to be able to display the name associated with the author  
of each comment. The iteration in my view looks like this:

\<% for comment in @comments -%\>  
  
on \<%= comment.created\_at.strftime(’%m-%d-%Y’) %\> @  
\<%= comment.created\_at.strftime(’%I:%M’) %\> BLANK said:  
  
\<%= white\_list comment.comment %\>  
  
\<% end -%\>

I would like to interchange the BLANK with the commentors name. Each  
PhotoComment object has a user\_id field which stores the user id for  
the author of the comment. This name is stored in another table  
called users. How do I append this name into the @comments hash? Is  
this how you do it? or do you create another variable for the author  
names? Thanks.

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [March 6, 2008, 10:29am UTC](https://www.ruby-forum.com/t/comments-with-name/131129/2 "2008-03-06T10:29:06Z")

</div>

that is absolutely amazing…thank you

On Mar 6, 1:14 am, Thorsten M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [March 6, 2008, 10:14am UTC](https://www.ruby-forum.com/t/comments-with-name/131129/3 "2008-03-06T10:14:24Z")

</div>

> \<% for comment in @comments -%\>  
>   
> on \<%= comment.created\_at.strftime(’%m-%d-%Y’) %\> @  
> \<%= comment.created\_at.strftime(’%I:%M’) %\> BLANK said:  
>   
> \<%= white\_list comment.comment %\>  
>   
> \<% end -%\>

ok, in model PhotoComment:

belongs\_to :user

and then simply replace BLANG with:  
\<%= comment.user.name %\>

(assuming, the users name is stored in name…)
