::加载ActiveModel ForbiddenAttributesError [英] ActiveModel::ForbiddenAttributesError

查看:84
本文介绍了::加载ActiveModel ForbiddenAttributesError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注如何在这里创建和安装引擎。创建的博客文章当我试图评论时,它返回Brough :: CommentsController#create中的ActiveModel :: ForbiddenAttributesError错误。
评论控制器

i've been following rails guide on creating and mounting an engine here.Created blog post and when i tried to comment ,it returned "ActiveModel::ForbiddenAttributesError in Blorgh::CommentsController#create " error. Comment controller

    require_dependency "blorgh/application_controller"

module Blorgh
  class CommentsController < ApplicationController
    def create
      @post = Post.find(params[:post_id])
      @comment = @post.comments.create(params[:comment])
      flash[:notice] = "Comment has been created!"
      redirect_to posts_path
    end
  end
end

这里是评论模型

and here is comment model

 module Blorgh
  class Comment < ActiveRecord::Base

  end
end

如何解决问题是什么?

推荐答案

我猜你正在使用rails 4.你需要在这里标记所有必需的参数
去::

I guess you are using rails 4. You need to mark all the required parameters here it goes :

   def create
      @post = Post.find(params[:post_id])
      @comment = @post.comments.create(post_params)
      flash[:notice] = "Comment has been created!"
      redirect_to posts_path
    end

    def post_params
      params.require(:blorgh).permit(:comment)
    end

hope 此链接帮助...

hope this link helps...

这篇关于::加载ActiveModel ForbiddenAttributesError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆