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.
Can't mass assign protected attributes
-
21-04-2022 - |
Question
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?
Solution
OTHER TIPS
attr_accessible :severity
Section 6: Mass Assignment http://guides.rubyonrails.org/security.html
Your seed says severity
, but your accessor says severity_id
. So which one is it?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow