Reputation: 669
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'
app/controllers/posts_controller.rb:46:in
create'
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.
Upvotes: 2
Views: 3627
Reputation: 21
You can try this,
In your PostsController model add all attributes used in the form such as,
class PostsController < ActiveRecord::Base
attr_accessible :name, :content, :title
...
...
end
it works for me.
Upvotes: 0
Reputation: 32627
In your model, you need to add tag_attributes
to the attr_accessible
call.
For example :
class User < ActiveRecord::Base
attr_accessible :tags_attributes
end
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.
Upvotes: 3