Muhammad Faisal Iqbal
Muhammad Faisal Iqbal

Reputation: 1836

ForbiddenAttributesError with Active Admin

I 've just started working on ROR. I made blog app following strictly ROR official doc. It worked fine for CRDU. Now I added Active Admin to it, it works fine on delete but gives error while creatiing/updating focusing on raise ActiveModel::ForbiddenAttributesError

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

In Controller, I'm using 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

Upvotes: 4

Views: 3176

Answers (1)

Nitin
Nitin

Reputation: 7366

I think you didn't add permit_params in your active admin file.

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

Look into this link for more detail.

Upvotes: 6

Related Questions