0

我有两个模型——FamilyPerson :(使用 Mongoid 和 Rails 3.2.13)

家庭.rb

attr_accessible :location  
has_many :persons
accepts_nested_attributes_for :persons  

人.rb

attr_accessible :name
belongs_to :family  

FamiliesController我有:

  def edit
   @family=Family.find(params[:id])
  end

  def update
    @family=Family.find(params[:id])
    @family.update_attributes(params[:family])
  end  

在家庭控制器 的edit.html.erb中:

<div class="container">
<%= simple_form_for @family do |f| %>
  <%= f.error_messages %>
    <%= f.input :location %>
    <%= f.simple_fields_for :persons do |p| %>
      <%= p.input :name %>
    <%end%>
  <%= f.submit "Submit" %>
<% end %>
</div>  

它只更新家庭属性,人物属性保持不变。

我如何也更新 Person 的属性?

我还想delete为每个人添加一个按钮,该按钮将删除相应的人。如何做到这一点?

4

1 回答 1

1

尝试添加persons_attributes#inattr_accessiblefamily.rb

于 2013-09-21T07:46:59.343 回答