NoMethodError in Posts#show error in section 6.4 of RailsGuides
I am trying to follow the RailsGuides,
http://edgeguides.rubyonrails.org/getting_started.html
Now, in section 6.4 where I am supposed to be able to add comments in my
blog site, I am encountering this error:
NoMethodError in Posts#show Showing
C:/Sites/blog/app/views/posts/show.html.erb where line #12 raised:
undefined method `comments' for #
below is the snippet in my show.html.erb
<h2>Add a comment:</h2>
<%= form_for([@post, @post.comments.build]) do |f| %>
<p>
<%= f.label :commenter %><br>
<%= f.text_field :commenter %>
Below is the snippet for my comments controller:
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create(comment_params)
redirect_to post_path(@post)
end
private
def comment_params
params.require(:comment).permit(:commenter, :body)
end
end
Please help me thanks.
-aguds
No comments:
Post a Comment