0

I am trying to edit a view called categories in my project,but I seems to get a very strange error while trying to do so.

The error which is shown is as follows:-

    ActiveModel::MassAssignmentSecurity::Error in CategoriesController#update

    Can't mass-assign protected attributes: id, name, parent_cat_id

Parameters:

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"RaQQRvJRRmjg0HAy3utlrD2wKAvYXbtNC2hjR4JHpXs=",
 "category"=>{"id"=>"3",
 "name"=>"Non-Fictional",
 "parent_cat_id"=>"0"},
 "commit"=>"Update",
 "id"=>"3"}

My category table is as follows:-

id serial NOT NULL,
  name character varying(255),
  parent_cat_id integer DEFAULT 0,
  deleted integer NOT NULL DEFAULT 0,
  CONSTRAINT categories_pkey PRIMARY KEY (id)

My category model file is as follows:-

class Category < ActiveRecord::Base

    attr_accessible :name, :parent_cat_id

    # ------- ASSOCIATIONS -----------

    has_many :books

    belongs_to :category, :foreign_key => 'parent_cat_id'
end

Can anyone please help me with this

SemperFi
  • 2,358
  • 6
  • 31
  • 51

1 Answers1

0

Add fields(id, name, parent_cat_id) to Category model which should be mass-assigned -

class Category < ActiveRecord::Base
  attr_accessible :name, :parent_cat_id, :id
    # ------- ASSOCIATIONS -----------
  has_many :books
  belongs_to :category, :foreign_key => 'parent_cat_id'
end
sjain
  • 23,126
  • 28
  • 107
  • 185