簡體   English   中英

在引導選項卡中渲染嵌套表單

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM