# NewbieQ: Redisplaying Categorized Comments

**URL:** <https://www.ruby-forum.com/t/newbieq-redisplaying-categorized-comments/88366>\
**Category:** Rails\
**Created:** [March 10, 2007, 1:41am UTC](https://www.ruby-forum.com/t/newbieq-redisplaying-categorized-comments/88366 "2007-03-10T01:41:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebrad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/13edae/32.png) [@ebrad](https://www.ruby-forum.com/u/ebrad)\
**Post date:** [March 10, 2007, 1:41am UTC](https://www.ruby-forum.com/t/newbieq-redisplaying-categorized-comments/88366/1 "2007-03-10T01:41:37Z")

</div>

Greetings,  
As my first web app with Rails I am creating an HR Tracking program.  
There are employee ‘records’ that can have ‘comments’ added to each  
record. I also assign each comment a category such as ‘general note’,  
‘disciplinary action’, or ‘job changes’ which I’ve set in my Comments  
table using the values either 0, 1, or 2.

I can create the comments fine, but difficulty I am having is  
seperating the comments into different areas of the employee record  
page based on the category. So, for example, if I want to add a  
comment like ‘Employee was promoted to manager’ and assign it a  
category of ‘job changes’, I would then want that comment to display  
in a list below the heading ‘Job Changes’ on that records ‘show’ page  
just above the comment form.

The best way I can think of is doing something like:  
\<% if comment\_type = 1 %\>  
\<% for comment in @record.comments %\>  
\<% end %\>  
\<% end %\>  
but I can’t seem to get the syntax correct. Can anyone assist? Below  
is my code and layout.

* * *

APP/CONTROLLERS/RECORDS\_CONTROLLER.RB

## def comment Record.find(params[:id]).comments.create(params[:comment]) flash[:notice] = “Added your comment.” redirect\_to :controller =\> “records”, :action =\> “show”, :id =\> params[:id] end

APP/VIEWS/RECORD/SHOW.RHTML

Job Change Comments \<% for comment in @record.comments %\> Submitted: \<%= comment.created\_at %\>  
\<%=h comment.body %\>
* * *
 \<% end %\> Add a Comment \<%= form\_tag :action =\> "comment", :id =\> @record %\> \<%= text\_area "comment", "body", "cols" =\> 40, "rows" =\> 5 %\>  
 Comment Type  
 \<%= select( :comment, :comment\_type, [['General', 0], ['Disciplinary', 1],['Job Change', 2]]) %\>  
  
 \<%= submit\_tag "Save" %\>
## 

COMMENTS TABLE STRUCTURE

id (int)  
body (text)  
created\_at (datetime)  
comment\_type (int)  
record\_id (int)
