2015-12-21 75 views
4

我刚刚开始研究ROR。 我严格遵循ROR官方文档制作了博客应用程序。 它适用于CRDU。 现在我添加的活性管理员给它,它适用于精细删除但给同时creatiing /更新重点 加载ActiveModel养错误:: ForbiddenAttributesErrorForbiddenAttributesError with Active Admin

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

在控制器中,我使用下面的代码:

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 

回答

2

我想你并没有在你的活动管理文件中加入permit_params

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

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

+0

谢谢迪帕克 它的工作 –