0
我有一个Rails 3应用程序,其中包括这两个模型:costproject
和costestimate
。Rails accept_nested_attributes_for未显示记录
的costproject
模型包含:
has_many :costestimates
accepts_nested_attributes_for :costestimates
的costestimate
记录每个costproject
自动创建的 - 所以他们总是存在的。
我试图创建一个表单更新所有的costestimate
记录特定costproject
我的表单包含:
<%= form_for @costproject do |f| %>
...
<% f.fields_for :costestimates do |builder| %>
<tr>
<td><%= builder.number_field :amount %></td>
<td><%= builder.text_area :notes, :rows => 3 %></td>
</tr>
...
但是,没有一个costestimate
记录的形式显示出来。
感谢您的帮助!
如果你改变'f.fields_for会发生什么? '到变种'@costproject.costestimates.each do | builder |'?另外,您是否在您的Costproject模型中将':costestimates_attributes'添加到'attr_accessor'? – sixty4bit 2015-04-03 15:37:56
我认为'f.fields_for ...'是我所做的事情需要的吗? – Reddirt 2015-04-03 16:14:06