后,我在Rails的4个工作,并已得到惨惨很好地与奉this issue,一个使用案例,我觉得可能是比较常见的工作,除了。Rails的4惨惨:未知属性错误包括load_and_authorize_resource
我有一个Comment
模型,其中has_many :comments, through: :replies
为嵌套评论。所有这些都运行良好,直到我将load_and_authorize_resource
添加到我的评论控制器。这个问题似乎源自一个隐藏字段,它向我的创建操作发送可选的:parent_comment_id
属性。
我已经允许通过强大的参数此属性:
def comment_params
params.require(:comment).permit(:content, :parent_comment_id, :post_id, :comment_id, :user_id)
end
所以,我可以建立关联,如果:parent_comment_id
包括:
if comment_params[:parent_comment_id] != nil
Reply.create({:parent_comment_id => comment_params[:parent_comment_id], :comment_id => @comment.id})
end
但是,一旦我添加load_and_authorize_resource
,我得到一个未知属性错误为:parent_comment_id
。我错过了什么?