title: Can't create a form for comments in a post RAILS
body: <p>I'm trying to create a comment box/form under my article in rails, but it keeps raising an error saying unknown attribute: post_id</p>
  
  <p>My form code </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 :body %&gt; &lt;br&gt;
  &lt;%= f.text_area :body %&gt;
  &lt;/p&gt;
  &lt;p&gt;
  &lt;%= f.submit %&gt;
  &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>For my comment create action</p>
  
  <pre><code>def create
  @post = Post.find(params[:post_id])
  @comment = @post.comments.build(comment_params)
  redirect_to post_path(@post)
  
  respond_to do |format|
    if @comment.save
      format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
      format.json { render action: 'show', status: :created, location: @comment }
    else
      format.html { render action: 'new' }
      format.json { render json: @comment.errors, status: :unprocessable_entity }
    end
  end
  end
  </code></pre>
  
  <p>It raises an error for </p>
  
  <pre><code>&lt;%= form_for ([@post, @post.comments.build]) do |f| %&gt;
  </code></pre>
  
  <p>saying unknown attribute: post_id</p>
  
  <p>Thanks all!</p>
  
  <p>Updated Error : undefined method `posts'</p>
  
  <pre><code>&lt;tr&gt;
         &lt;td&gt;&lt;%= comment.commenter %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= comment.body %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= comment.posts %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= link_to 'Show', comment %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= link_to 'Edit', edit_comment_path(comment) %&gt;&lt;/td&gt;
         &lt;td&gt;&lt;%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %&gt;&lt;/td&gt;
  </code></pre>