ForbiddenAttributesError with Active Admin

I just started working on ROR. I made a blog application strictly following the official ROR doc. It worked great for CRDU. Now I added Active Admin to it, it works fine when uninstalling, but gives an error when creating / updating Raise ActiveModel :: ForbiddenAttributesError

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

In the controller, I use the following code:

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
+4
source share
1 answer

I think you have not added permit_paramsan administrator to your active file.

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

See this link for more details.

+2
source

Source: https://habr.com/ru/post/1621097/


All Articles