在Rails 5上工作 我正在尝试在每个动态标签中呈现嵌套表单(相同模型), 但是现在在所有选项卡中都呈现相同的格式,如何在不同的选项卡中呈现不同的字段集
views / material_masters / new.html.erb
var dbvar;
...
.then(() => {
//var dbvar; <-- delete this line
dbvar=1; // <- can access outer dbvar
console.log(dbvar); //Log HERE
...
视图/material_masters/_material_location_fields.html.erb
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="tabbable-line">
<ul class="nav nav-tabs ">
<% @part_locations.each.with_index do |l, i| %>
<li <%= 'class="active"' if i == 0 %>>
<a href="#<%= l.location_name %>" data-toggle="tab"> <%= l.location_name %> </a>
</li>
<% end %>
<li><button type="button" class="fa fa-plus btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal"></button> </li>
</ul>
<div class="tab-content">
<% @part_locations.each.with_index do |l, i| %>
<div class="tab-pane <%= 'active' if i == 0 %>" id="<%= l.location_name %>">
<%= f.fields_for :material_locations do |builder| %>
<%= render 'material_location_fields', :f => builder %>
<% end %>
<%= link_to_add_association "Add", f, :material_locations, class: "btn btn-primary btn-xs" %>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
模型/material_master.rb
<fieldset>
<div class= "nested-fields">
<div class="col-sm-3">
<%= f.label :material_location, "Material Location" %>
<%= f.text_field :mat_location,class:"form-control",required: true %>
</div>
<div class="col-sm-3">
<%= f.label :opening_stock %>
<%= f.text_field :opening_stock ,class:"form-control",onKeyPress:"return NumbersOnly(this, event,true)",required: true %>
</div>
<div class="col-sm-3">
<%= f.label :reorder_qty %>
<%= f.text_field :reorder_qty, class:"form-control",onKeyPress:"return NumbersOnly(this, event,true)",required:true %>
</div>
</div>
</fieldset>
https://i.stack.imgur.com/b6Ssr.png
https://i.stack.imgur.com/69h3X.png
听见,我想在bangalore标签中添加位置,我正在添加孟买的位置,在delhi标签中,我想添加一个实质性的位置,但是下一个标签中将出现相同的表格
答案 0 :(得分:0)
您的代码上显然有一行空格:
<a href="#<%= l .location_name %>" data-toggle="tab"> <%= l.location_name %> </a>
您可以注意到l .location_name可以删除空格吗?