【发布时间】:2015-10-01 19:45:36
【问题描述】:
当我创建与帖子相关的评论时,我收到此错误::
我的 cmets 控制器 ::
class CommentsController < ApplicationController
def new
@comments = Comment.new
end
def create
@post = Post.find (params[:post_id])
@comments = @post.comments.create(params[:comments].permit(:commenter, :body))
redirect_to post_path(@post)
end
end
// cmets 的表单 ///
<strong>Title:</strong>
<%= @post.Title %>
</p>
<p>
<strong>Text:</strong>
<%= @post.Text %>
</p>
<%= 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 %>
我在这一行遇到错误::
@comments = @post.comments.create(params[:comments].permit(:commenter, :body))
请指出我错在哪里..
一次编辑 :: 我的实际错误声明 ::
NoMethodError in CommentsController#create
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4