我正在为我的一张表创建种子数据,每当我运行 rake db:seed 时,它都会给我错误:
无法批量分配受保护的属性:严重性
我的两个模型看起来像
class Status < ActiveRecord::Base
belongs_to :severity
attr_accessible :description, :image, :name, :slug, :severity_id
end
和
class Severity < ActiveRecord::Base
attr_accessible :name, :val, :severity_id
end
我试图播种的数据是
statuses = Status.create(
[
{
"name"=> 'Normal',
"slug"=> 'normal',
"description"=> 'The service is up or was up during this entire period',
"severity"=> 1,
"image"=> 'tick-circle'
}
]
)
为什么会这样?