我的应用程序中有invoice和invoice_items模型。我已经使用cocoon gem来嵌套models.i我正在使用rails 4.2。它在我创建新发票时工作正常,但当我点击我的编辑按钮时,我得到“模板缺失错误”,虽然我在我的应用程序中有_invoice_item_fields.html.erb文件。
这是我的_form.html.erb文件
<div class=" form">
<%= form_for(@invoice,:html=>{:class=>"cmxform form-horizontal tasi-form",:novalidate=>"novalidat"}) do |f| %>
<% if @invoice.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@invoice.errors.count, "error") %> prohibited this invoice from being saved:</h2>
<ul>
<% @invoice.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group ">
<%= f.label :billing_address ,:class=>"control-label col-lg-2" %>
<div class="col-lg-6">
<%= f.text_area :billing_address,:class=>"form-control" %>
</div>
</div>
<div class="form-group ">
<%= f.label :shipping_address ,:class=>"control-label col-lg-2" %>
<div class="col-lg-6">
<%= f.text_area :shipping_address,:class=>"form-control" %>
</div>
</div>
<div class="form-group ">
<%= f.label :company_id ,:class=>"control-label col-lg-2" %>
<div class="col-lg-6">
<%= f.number_field :company_id,:class=>"form-control" %>
</div>
</div>
<div class="form-group ">
<%= f.label :invoice_date ,:class=>"control-label col-lg-2" %>
<div class="col-lg-6">
<%= f.date_select :invoice_date,:class=>"form-control" %>
</div>
</div>
<div class="form-group ">
<%= f.label :status ,:class=>"control-label col-lg-2" %>
<div class="col-lg-6">
<%= f.number_field :status,:class=>"form-control" %>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<section class="panel">
<header class="panel-heading">
Invoice Items
<span class="pull-right">
<%= link_to_add_association 'Add Item', f, :invoice_items,:class=>"btn btn-default"%>
</span>
</header>
<div class="panel-body">
<div class="adv-table">
<%= f.fields_for :invoice_items do |item| %>
<%= render '_invoice_item_fields', :f => item %>
<% end %>
</div>
</div>
</section>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<%= f.submit "Save",:class=>"btn btn-danger"%>
</div>
</div>
<% end %>
</div>
这是我的_invoice_item_fields.html.erb文件
答案 0 :(得分:1)
此...
<%= render '_invoice_item_fields', :f => item %>
必须是
<%= render 'invoice_item_fields', :f => item %>
您不要在Rails _
调用中使用前导render
来呈现部分内容。下划线仅用于磁盘上的文件名。