Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin nested form duplicate

Tags:

I know there are multiple questions with a similar title to this, but I haven't found anything that resembled my problem. If there is already a solution and thus my question is a duplicate, I'm sorry - I just didn't find it, it's not that I didn't search.

I'm using ActiveAdmin with the ActiveSkin theme. I have a form for my model Agent where I want to use the nested forms for a has_many relation. I created this code in a partial:

<%= semantic_form_for [@agent], builder: ActiveAdmin::FormBuilder do |f| %>
    <%= f.semantic_errors %>
    <%= f.inputs 'General Information' do %>
        <%= f.input :name %>
        <%= f.input :description %>
    <% end %>
    <%= f.inputs 'Capture Columns' do %>
        <%= f.has_many :capture_columns, new_record: 'Add Column' do |column| %>
            <%= column.input :column_name %>
            <%= column.input :column_datatype %>
        <% end %>
    <% end %>
    <%= f.actions do %>
        <%= f.action :submit %>
        <li class="cancel"><%= link_to 'Cancel', :back %></li>
    <% end %>
<% end %>

Basically, this is working, but it looks like this:

Forms with duplicated html

Why is the html duplicated (I checked it, it's exactly the same)? What am I doing wrong?

EDIT: The inner HTML for the nested form is duplicated, too: Nested Form with duplicated html

like image 920
Florian Koch Avatar asked Mar 13 '17 13:03

Florian Koch


1 Answers

Not saying it's the right behavior, but according to the docs, you need to avoid printing to the template when using has_many.

Try using <%- or <% instead of <%= in the f.has_many declaration and block.

like image 102
deivid Avatar answered Oct 04 '22 17:10

deivid