0

I have model CustomerBio and CustomerBioDetail. The details have different category.

CustomerBio model has_many CustomerBioDetails

CustomerBioDetail belongs_to CustomerBio

    <%= 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 %>

How I will put my nested into tabs by its category.

sample 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

So I will have 2 tabs for this

4

1 回答 1

3

我自己没有尝试过,但这应该对你有用:

<%= 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 %>
于 2015-09-14T07:09:21.807 回答