我有两个模型——Family和Person :(使用 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
为每个人添加一个按钮,该按钮将删除相应的人。如何做到这一点?