# Problem with error\_messages

**URL:** <https://www.ruby-forum.com/t/problem-with-error-messages/93231>\
**Category:** Rails\
**Created:** [April 29, 2007, 6:02pm UTC](https://www.ruby-forum.com/t/problem-with-error-messages/93231 "2007-04-29T18:02:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zavulon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@zavulon](https://www.ruby-forum.com/u/zavulon)\
**Post date:** [April 29, 2007, 6:02pm UTC](https://www.ruby-forum.com/t/problem-with-error-messages/93231/1 "2007-04-29T18:02:47Z")

</div>

Hi all,

I have a problem with error\_messages displaying correctly. I have a page  
to show an item. That page has a comment form (which calls to the  
controller ‘comment’ with action ‘create’) and below a list of comments  
for that item.

The problem is, when I submit a comment that doesn’t pass validation,  
error messages are not displayed. I think it’s because I have the  
comments form ‘embedded’ on the ‘show’ page. Here is my code, I tried to  
trim as much stuff as possible:

Item view: show.rhtml:

…  
\<%= render(:partial =\> ‘item’, :locals =\> { :item =\> @item }) -%\>

…

\<%= start\_form\_tag :controller =\> ‘comments’, :action =\> ‘create’,  
:item\_id =\> @item.id %\>  
\<%= render :partial =\> ‘new\_comment\_form’ %\>

\_new\_comment\_form.rhtml:

…  
\<%= error\_messages\_for ‘comment’ %\>

…

 \<%= end\_form\_tag %\>

comments\_controller.rb:

def create  
@comment = Comment.new(params[:comment])

```
...

if @comment.save
  flash[:notice] = 'Thank you! Comment added successfully.'
  redirect_to :controller => 'items', :action => 'show', :id =>

```

@comment.item\_id  
else  
render :controller =\> ‘items’, :action =\> ‘show’  
end  
end
