I have a devise model that embeds many for two other models called has_skills and desires_skills. The attr-accessibles are in place but I still get a WARNING: Can’t mass-assign protected attributes: my_skills_attributes, wanted_skills_attributes error message. Below are my models. Thoughts?
class User
include Mongoid::Document
embeds_many :wanted_skills
embeds_many :my_skills
accepts_nested_attributes_for :my_skills, allow_destroy: true
accepts_nested_attributes_for :wanted_skills, allow_destroy: true
.........
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :location, :my_skills, :wanted_skills, :name, :sname
My Skills model
class MySkill
include Mongoid::Document
embedded_in :user
field :name
attr_accessible :name
end
My has skills model
class WantedSkill
include Mongoid::Document
embedded_in :user
field :sname
attr_accessible :sname
end
Lastly my form
<%= simple_nested_form_for @user do |f| %>
<%= f.fields_for :my_skills do |task| %>
<%= task.label :name %><br />
<%= task.text_field :name %><br />
<%= task.link_to_remove "Remove this task" %>
<% end %>
<p><%= f.link_to_add "Add a task", :my_skills %></p>
<%= f.fields_for :wanted_skills do |task| %>
<%= task.label :sname %><br />
<%= task.text_field :sname %><br />
<%= task.link_to_remove "Remove this task" %>
<% end %>
<p><%= f.link_to_add "Add a task", :wanted_skills %></p>
<div><%= f.submit "Sign up" %></div>
<% end %>
To make the nested attributes work, you need to allow
my_skills_attributesand notmy_skills. Thats all.