[英]Render nested form in bootstrap tab
在Rails 5上工作,我试图在每个动态选项卡中渲染嵌套表单(相同模型),但是现在在所有选项卡中都渲染相同的格式,如何在不同的选项卡中渲染不同的字段集
视图/ material_masters / new.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_masters / _material_location_fields.html.erb
<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>
模型/ material_master.rb
class MaterialMaster < ApplicationRecord
has_many :material_locations
accepts_nested_attributes_for :material_locations,allow_destroy: true
end
https://i.stack.imgur.com/b6Ssr.png
https://i.stack.imgur.com/69h3X.png
听到我想在班加罗尔标签中添加位置,在孟买位置中添加孟买,在德里标签中,我想添加一个其他材料位置,但下一个标签中将出现相同的表格
您的代码上明显的是一行中有空格:
<a href="#<%= l .location_name %>" data-toggle="tab"> <%= l.location_name %> </a>
如您所知l .location_name可以删除空格吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.