活动管理表单:has_many 按条件在单独的面板中输入

Active Admin form: has_many inputs in separate panels by condition

我正在尝试使用 active admin 和 formtastic 创建一个表单,其中特定类型的评论在单独的面板上编辑,目前我通过 .html.erb 部分呈现面板,如下所示:

<div class="panel">
  <h3>Admin Reviews</h3>
  <div class="panel_contents">
    <div>
      <% f.has_many :reviews, heading: false, new_record: true, allow_destroy: false do |review| %>
        <% next unless review.object.reviewer_type === "Admin" %>
        <%= render partial: "admin/admin_reviews", locals: { r: review } %>
        <% review.input :_destroy, :as => :boolean, :label => "Delete" %>
      <% end %>
    </div>
  </div>
</div>

<div class="panel">
  <h3>Reviews</h3>
  <div class="panel_contents">
  <div>
    <% f.has_many :reviews, heading: false, new_record: true, allow_destroy: false do |review| %>
       <% next if review.object.reviewer_type === "Admin" %>
       <%= render partial: "admin/form_reviews", locals: { r: review } %>
       <% review.input :_destroy, :as => :boolean, :label => "Delete" %>
    <% end %>
  </div>
</div>

但我更愿意做一些事情,比如去掉为每个被迭代的评论生成的空白 div,它属于另一个面板 (blank div):

<div class="panel">
  <h3>Admin Reviews</h3>
  <div class="panel_contents">
    <div>
      <% admin_reviews = Review.where(reviewer_type: "Admin") %>
      <% f.has_many admin_reviews, heading: false, new_record: true, allow_destroy: true do |review| %>
        <%= render partial: "admin/admin_reviews", locals: { r: review } %>
      <% end %>
    </div>
  </div>
</div>

<div class="panel">
  <h3>Reviews</h3>
  <div class="panel_contents">
  <div>
    <% reviews = Review.where.not(reviewer_type: "Admin") %>
    <% f.has_many reviews, heading: false, new_record: true, allow_destroy: true do |review| %>
       <%= render partial: "admin/form_reviews", locals: { r: review } %>
    <% end %>
  </div>
</div>

以上内容不起作用,但我希望它传达了我对没有空白 div 的更简洁解决方案的需求,我正在考虑使用 javascript.

隐藏这些空白 div
<div class="panel">
  <h3>Reviews</h3>
    <div class="panel_contents">
      <div>
        <% f.has_many :reviews, for: [:reviews, f.object.non_admin_reviews], heading: false, new_record: true, allow_destroy: true do |review| %>
          <%= render partial: "admin/tutors/form_tutor_reviews", locals: { r: review } %>
        <% end %>
     </div>
   </div>
</div>