I don’t understand where is :post_id and :comment came from to ‘create’ action. There is no reference to them in from_for function. http://guides.rubyonrails.org/getting_started.html “7.4 Generating a Controller”:
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create(params[:comment])
redirect_to post_path(@post)
end
end
form_for([@post, @post.comments.build])will produce a form with the action of a url “create a comment for a post”, this url has thepost_id. And the:commentcomes from the form element, which has name attribute likename="comment[commenter]"(which comes from :<%= f.text_field :commenter %>),name="comment[body]"(which comes from:<%= f.text_area :body %>) and so on.