0

我有一个设计模型,其中嵌入了许多其他模型,称为 has_skills 和desireds_skills。attr-accessibles 已就位,但我仍然收到警告:无法批量分配受保护的属性:my_skills_attributes,wanted_skills_attributes 错误消息。下面是我的模型。想法?

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

我的技能模型

class MySkill
  include Mongoid::Document
  embedded_in :user
  field :name

  attr_accessible  :name
end

我的技能模型

class WantedSkill
 include Mongoid::Document
 embedded_in :user
 field :sname
 attr_accessible  :sname

结尾

最后是我的表格

<%= 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 %>

4

1 回答 1

0

要使嵌套属性起作用,您需要允许my_skills_attributes而不是my_skills. 就这样。

attr_accessible :my_skills_attributes
于 2012-04-21T18:22:06.237 回答