加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 带有Active Admin的ForbiddenAttributesError

发布时间:2020-12-17 02:25:23 所属栏目:百科 来源:网络整理
导读:我刚刚开始研究ROR. 我严格按照ROR官方文档制作博客应用程序. 它适用于CRDU. 现在我添加了Active Admin,它在删除时工作正常,但在创建/更新时会出现错误 引发ActiveModel :: ForbiddenAttributesError def sanitize_for_mass_assignment(attributes) if attri
我刚刚开始研究ROR.
我严格按照ROR官方文档制作博客应用程序.
它适用于CRDU.
现在我添加了Active Admin,它在删除时工作正常,但在创建/更新时会出现错误
引发ActiveModel :: ForbiddenAttributesError

def sanitize_for_mass_assignment(attributes)
    if attributes.respond_to?(:permitted?) && !attributes.permitted?
      **raise ActiveModel::ForbiddenAttributesError**
    else
      attributes
    end

在Controller中,我使用以下代码:

def create
  @article = Article.new(article_params)

  if @article.save
    redirect_to @article
  else
    render 'new'
  end
end
def update
  @article = Article.find(params[:id])

  if @article.update(article_params)
    redirect_to @article
  else
    render 'edit'
  end
end
def destroy
  @article = Article.find(params[:id])
  @article.destroy

  redirect_to articles_path
end

private
  def article_params
    params.require(:article).permit(:title,:text,:AuthorAge)
  end

解决方法

我认为您没有在您的活动管理文件中添加permit_params.

# app/admin/xyz.rb
permit_params :comma separated attributes.

查看this链接了解更多详情.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读