title: Showing error messages for nested resources in Rails
body: <p>I am creating my first app, simple blog, and I don't know how to show error messages for nested resource(comments) that doesn't pass validation.</p>
  
  <p>this is create action for comments: </p>
  
  <pre><code>  def create
      @post = Post.find(params[:post_id])
      @comment = @post.comments.create(comment_params)
      redirect_to post_path(@post)
    end
  </code></pre>
  
  <p>this is comment form:</p>
  
  <pre><code>  &lt;%= form_for([@post, @post.comments.build]) do |f| %&gt;
      &lt;p&gt;
        &lt;%= f.label :commenter %&gt;&lt;br /&gt;
        &lt;%= f.text_field :commenter %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;%= f.label :text %&gt;&lt;br /&gt;
        &lt;%= f.text_area :text %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;%= f.submit %&gt;
      &lt;/p&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>I tried with:</p>
  
  <pre><code>  def create
      @post = Post.find(params[:post_id])
      @comment = @post.comments.build(comment_params)
  
      if @comment.save
        redirect_to post_path(@post)
      else
        render '/comments/_form'
      end
    end
  </code></pre>
  
  <p>and: </p>
  
  <pre><code>  &lt;% if @comment.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;
          &lt;%= pluralize(@comment.errors.count, "error") %&gt; prohibited
          this comment from being saved:
        &lt;/h2&gt;
        &lt;ul&gt;
          &lt;% @comment.errors.full_messages.each do |msg| %&gt;
            &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
          &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>But I don't know whats wrong.</p>