# Problem with comment validation

**URL:** <https://www.ruby-forum.com/t/problem-with-comment-validation/144839>\
**Category:** Rails\
**Created:** [August 2, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/problem-with-comment-validation/144839 "2008-08-02T23:13:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bryan](https://www.ruby-forum.com/u/bryan)\
**Post date:** [August 2, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/problem-with-comment-validation/144839/1 "2008-08-02T23:13:58Z")

</div>

I’m a new Rails programmer and I’ve been working on a simple blog  
application to get started. But I have this problem with comment  
validation.

I’m using REST throughout my entire app, and I have the comments  
resource nested under the posts resource. I’m using a form on the show  
action of my posts controller for submitting the comments. The form  
goes to post\_comments\_path(@post.id) and the comments will submit  
properly, that part works. But if the model doesn’t validate, I can’t  
get the browser to reload the show action and display what the user  
originally typed in on the form, along with the errors.

My main question is, how do I display the errors if the form is under  
a different controller (as well as “save” what the user types in)?

Here’s my form that displays on the show action:

\<% form\_for [:post, @comment], :url =\> post\_comments\_path(@post.id) do  
|f| %\>

**Add comment:**

\<%= error\_messages\_for :comment %\>

\<%= f.text\_field :author %\> _Name_

\<%= f.text\_field :email %\> _Email (will not be displayed)_

\<%= f.text\_area :body, :rows =\> 10 %\>

\<%= submit\_tag 'Add comment' %\>

\<% end %\>

And here’s my create action in the comments controller:

def create  
@comment = Comment.new(params[:comment])  
if @post.comments \<\< @comment  
redirect\_to post\_path(@post.id)  
else  
# I don’t know what to put here  
end  
end

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![bryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bryan](https://www.ruby-forum.com/u/bryan)\
**Post date:** [August 2, 2008, 11:54pm UTC](https://www.ruby-forum.com/t/problem-with-comment-validation/144839/2 "2008-08-02T23:54:55Z")

</div>

Never mind. I just found the answer. But actually, there’s another  
problem now. Even though the record isn’t saved, the parts of the  
comment that are completed show up on the comment section. Is there a  
way to avoid this?
