5

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

4
  • Version of Rails? Version of ActiveAdmin? (try pre5). My first response would be to rewrite the partial in Arbre (.arb not .erb), eg. activeadmin.info/5-forms.html Commented Mar 18, 2017 at 19:22
  • Rails 5.0.2 and AA from the current master branch. why do you think that abre works better? Commented Mar 18, 2017 at 19:38
  • As Fivell mentions in the GH issue the tests cover using .arb much better than .erb, which is more of an afterthought. Commented Mar 18, 2017 at 23:13
  • 1
    f.inputs in Arbre overrides and is slightly different from f.inputs using just Formtastic. <%- as suggested is worth trying also. Commented Mar 18, 2017 at 23:27

2 Answers 2

3
+50

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm pretty sure it's going to work, I run into this myself yesterday! xD
I also had to use <% for the has_many block itself, but yeah, it works! Thanks a lot!
Yes, that's the only place that needs changing, actually! I'll clarify the answer.
no, I must not use <%= inside of has_many either, else the content is printed twice
mmmmm. I thought I tried this, but since this is what the docs say, and you have tried it for sure... I accepted your edit! Thanks :)
1

There is a loop hear. The problem is simple to solve, just get in the loop and understand why it is looping and how to fix it. You should use binding.pry to test it. You can set a breakpoint in the form with <% binding.pry %> or you can print variables like <% puts column %> in your server log.

  <%= f.has_many :capture_columns, new_record: 'Add Column' do |column| %>
        <%= column.input :column_name %>
        <%= column.input :column_datatype %>
    <% end %>

4 Comments

I'll give it a try
I struggled using pry, but I tried to debug it with the normal console and wasn't able to extract any useful information...
@FlorianKoch it would be helpful if you would print in you server log 2 variables <% puts f.capture_columns %> before the f.has_many :capture_columns and inside that <% puts column %> <% puts column.input %> Vielen Dank :)
the first (slightly modified to f.object.capture_columns) doesn't output anything, column is printed as #<ActiveAdmin::FormBuilder:0xd021068> and column.input isn't something I can put

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.