如何将嵌套表单放入选项卡中?

How to put in tabs the nested form?

我有模型 CustomerBio 和 CustomerBioDetail。详细信息有不同的类别。

CustomerBio 模型has_manyCustomerBioDetails

CustomerBioDetail belongs_toCustomerBio

    <%= simple_form_for @customer_bio, :remote => true do |f| %>
        ...
        <%= f.simple_fields_for :customer_bio_details, :wrapper => false do |p| %>
            <%= render 'customer_bio_detail_fields', {p: p} %>
        <% end %>   

        <%= f.submit 'Save', class: "btn btn-primary" %>
    <% end %>

我将如何按类别将我的嵌套放入选项卡中。

样本table:

CustomerBio


ID: 1
Name: Sample Question 1

CustomerBioDetail


ID: 1
customer_bio_id: 1
name: Full Name
category_id: 1

ID: 2
customer_bio_id: 1
name: Age
category_id: 1

ID: 3
customer_bio_id: 1
name: Company
category_id: 2

ID: 4
customer_bio_id: 1
name: Position
category_id: 2

所以我将为此设置 2 个标签

我自己没有尝试过,但这应该适合你:

<%= simple_form_for @customer_bio do |f| %>
  ...
  <% @customer_bio.customer_bio_details.group_by(&:category).each do |category, details| %>
    <div class="tab">
      <h3 class="tab-title"><%= category.name %></h3>
      <%= f.simple_fields_for details do |p| %>
        ...
      <% end %>
    </div>
  <% end %>

  <%= f.submit 'Save', class: "btn btn-primary" %>
<% end %>