2014-11-24 43 views
0

我正在rails上使用ruby创建一个博客。我正在使用在rails上使用较旧版本的教程。我正在尝试在同一页面上发布关于博客文章的评论。每当我点击提交按钮时,我都会收到此错误消息。 ::加载ActiveModel ForbiddenAttributesError使用老版本的红宝石的ActiveModel :: ForbiddenAttributesError?

提取的源(左右线#44):

def create 
@post = Post.find(params[:post_id]) 
@comment= @post.comments.new(params[:comment]) 

respond_to do |format| 
    if @comment.save 

这是我我的控制器内的代码

def create 
    @post = Post.find(params[:post_id]) 
    @comment= @post.comments.build(params[:comment]) 

    respond_to do |format| 
    if @comment.save 
     format.html { redirect_to @post, notice: 'Comment was successfully created.' } 
     format.json { render json: @post, status: :created, location: @comment } 
    else 
     format.html { render action: "new" } 
     format.json { render json: @post.errors, status: :unprocessable_entity } 
    end 
    end 

感谢您的帮助

+0

,你能否告诉comment.rb文件的线,说:'attr_asseccible',还发布表单代码。 – Surya 2014-11-24 05:25:32

回答

1

我想你正在使用Rails 4.如果是这样,所需的参数必须在控制器中标记为需要。

你可以参考http://stackoverflow.com/questions/17868427/rails-4-activemodelforbiddenattributeserror