我不知道怎么问这个。我如何以嵌套形式做到这一点。当我点击新建。我想从 customer_template_detail 填充我的 customer_answer_detail 的某些字段。我在嵌套表单中有 for 循环,但@customer_answer.customer_answer_details.build
在里面没有工作。
代码:
<%= simple_form_for @customer_answer do |f| %>
<%= f.simple_fields_for :customer_answer_details, :wrapper => false do |p| %>
<% @customer_template.customer_template_details.each do |ctd| %>
<div class="form-group">
<%= p.input :name, :as => :hidden, :input_html => { :value => ctd.name } %>
<%= p.input :customer_template_detail_id, :as => :hidden, :input_html => { :value => ctd.id } %>
<label class="col-sm-2 col-sm-2 control-label"><%= ctd.name %></label>
<div class="col-sm-10">
<%= p.input :answer,
:label => false,
:input_html => {:class => "form-control"} %>
</div><!-- /form col-sm-10-->
</div><!-- /form group-->
<% @customer_answer.customer_answer_details.build %>
<% end %>
<% end %>
<% end %>
你知道怎么做吗?