I’m almost finished step 11 on http://guides.rubyonrails.org/getting_started.html .
There is something wrong with my tags though, i keep getting this when trying to create a new post.
ActiveModel::MassAssignmentSecurity::Error in PostsController#create
Can’t mass-assign protected attributes: tags_attributes
Rails.root: /Users/david/blog
Application Trace | Framework Trace | Full Trace
app/controllers/posts_controller.rb:46:in new'create’
app/controllers/posts_controller.rb:46:in
Request
Parameters:
{"post"=>{"name"=>"David",
"content"=>"Foobar",
"title"=>"Programmer",
"tags_attributes"=>{"0"=>{"name"=>"Tea,
Cake"}}},
"utf8"=>"✓",
"commit"=>"Create Post",
"authenticity_token"=>"MhvAkAPcAey1Z4YXy7nKFmW/wETlu+USSvWOEBBN4po="}
I’ve been over and over every line of code containing the implementation of tags, and i can’t figure it out. Some guidance to what i should be looking for?
Thank you.
In your model, you need to add
tag_attributesto theattr_accessiblecall.For example :
If you already call it once, you can either add this field as an argument of the method, or make a second call. Both options are equivalent.
Having to specify all accessible parameters wasn’t a default until a few months.
This guide has been updated to reflect the change of default. But the new version hasn’t been deployed yet, this is why it’s not specified.
See Security: Mass Assignment