I was upgrading my project from Rails3 to Rails4 with this tutorial: RailsCasts
I have a model:
class Test < ActiveRecord::Base
validates :content, :presence => true, :length => { :minimum => 2 }
validates :name, :presence => true, :length => { :minimum => 2 }
validates :value, :presence => true
end
After upgrading, in rails console I tried to create new test object
Test.create(name: "asd", content:"asd", value: 5)
And got
WARNING: Can't mass-assign protected attributes for Achievement: name, content, value
(0.2ms) BEGIN
(0.2ms) ROLLBACK
=> #<Test id: nil, name: nil, content: nil, value: nil, created_at: nil, updated_at: nil>
Looks like I forgot to upgrade something. I tried to re-create rails application with overriding config and other rails files, but nothing changed.
I created new empty project and copied model files. It was working OK.
If I'll add
config.active_record.whitelist_attributes = false
to config/application.rb, my upgraded project will be working good. But it's not normal, because in empty rails4, this line was deleted.
What I forgot to upgrade or what must I do, to make upgraded project to work like empty created with rails4 and without config.activerecord ...?
UPD
raw_params = {:name => "asdasd", :content=>"asdasdasd", :value=>5}
=> {:name=>"asdasd", :content=>"asdasdasd", :value=>5}
2.0.0dev :002 > params = ActionController::Parameters.new(raw_params)
=> {"name"=>"asdasd", "content"=>"asdasdasd", "value"=>5}
2.0.0dev :003 > test = Test.create(params.permit(:name, :value, :content))
WARNING: Can't mass-assign protected attributes for Achievement: name, value, content
(0.2ms) BEGIN
(0.2ms) ROLLBACK
=> #<Test id: nil, name: nil, content: nil, value: nil, created_at: nil, updated_at: nil>