我正在尝试在我的项目中编辑一个名为 categories 的视图,但是在尝试这样做时似乎遇到了一个非常奇怪的错误。
显示的错误如下:-
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"}
我的类别表如下:-
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)
我的类别模型文件如下:-
class Category < ActiveRecord::Base
attr_accessible :name, :parent_cat_id
# ------- ASSOCIATIONS -----------
has_many :books
belongs_to :category, :foreign_key => 'parent_cat_id'
end
谁能帮我解决这个问题