I’m want to understand where author give :comment, which come to controller from this form
<h2>Add a comment:</h2>
<%= form_for([@post, @post.comments.build]) do |f| %>
<p>
<%= f.label :commenter %><br />
<%= f.text_field :commenter %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
And class and action is
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create(params[:comment])
redirect_to post_path(@post)
end
end
where author give :comment? how he can receive that without claiming in the form?
Because the
form_foris operating on an object of class Comment, the generated names for the fields namespace the params inparams[:comment].You could change this by passing the
:asoption toform_for, but this isn’t normally needed.