【发布时间】:2014-11-24 05:18:09
【问题描述】:
我正在使用 ruby on rails 创建一个博客。我正在关注在 Rails 上使用旧版本的教程。我正在尝试在同一页面上发布有关博客文章的 cmets。每当我点击提交按钮时,我都会收到此错误消息。 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
感谢您的帮助
【问题讨论】:
-
你能显示comment.rb文件的行,上面写着:
attr_asseccible,同时发布表单代码。
标签: ruby ruby-on-rails-4 ruby-on-rails-3.2