Ruby on rails 未定义的方法“许可证和x27”;零级:零级
当我创建与帖子相关联的评论时,我收到以下错误:: 我的意见:Ruby on rails 未定义的方法“许可证和x27”;零级:零级,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,当我创建与帖子相关联的评论时,我收到以下错误:: 我的意见: class CommentsController < ApplicationController def new @comments = Comment.new end def create @post = Post.find (params[:post_id]) @comments = @post.comments.create(params[
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
请指出我错在哪里
一个编辑::我的实际错误语句::
CommentsController中的NoMethodError\create正如错误消息所述,
参数[:comments]
为零
您应该使用params.require(:comments)。permit(:commenter,:body)
,这样,如果comments
不存在,它就不会继续了
此外,提交的实际参数是
注释
,而不是注释
。您可以通过查看日志中提交的参数来验证这一点。正如错误消息所述,params[:comments]
为零
您应该使用params.require(:comments)。permit(:commenter,:body)
,这样,如果comments
不存在,它就不会继续了
此外,提交的实际参数是
注释
,而不是注释
。您可以通过查看日志中提交的参数来验证这一点。使用强参数的正确语法是
params.require(:comments).permit(:commenter, :body)
但我认为params将包含注释
而不是注释
所以你应该使用
params.require(:comment).permit(:commenter, :body)
使用强参数的正确语法是
params.require(:comments).permit(:commenter, :body)
但我认为params将包含注释
而不是注释
所以你应该使用
params.require(:comment).permit(:commenter, :body)
thanx@Sevensacat::但是请告诉我你是怎么得到这个的。。我是新手。。p、 美国-它现在可以工作了。@user3322822它是《入门指南》的一部分-thanx@sevensacat::但是请告诉我你是如何得到这个的。。我是新手。。p、 它现在可以工作了。@user3322822它是《Rails入门指南》的一部分-