Reputation: 432
I'm creating seed data for one of my tables and whenever I run rake db:seed it gives me the error:
Can't mass-assign protected attributes: severity
My two models look like
class Status < ActiveRecord::Base
belongs_to :severity
attr_accessible :description, :image, :name, :slug, :severity_id
end
and
class Severity < ActiveRecord::Base
attr_accessible :name, :val, :severity_id
end
the data I'm trying to seed with is
statuses = Status.create(
[
{
"name"=> 'Normal',
"slug"=> 'normal',
"description"=> 'The service is up or was up during this entire period',
"severity"=> 1,
"image"=> 'tick-circle'
}
]
)
Why does this happen?
Upvotes: 2
Views: 124
Reputation: 6310
Your seed says severity
, but your accessor says severity_id
. So which one is it?
Upvotes: 1
Reputation: 2157
attr_accessible :severity
Section 6: Mass Assignment http://guides.rubyonrails.org/security.html
Upvotes: 2
Reputation: 303
You need to add :severity to the Severity model on the attr_accesible line . Rails is trying to assign an attribute by that name which I assume you have in your database.
Upvotes: 5