Question

I'm trying to create a form with active-admin in a new page with this code:

ActiveAdmin.register_page "Attach Logger" do
  content do
    semantic_form_for :project do |f|
      f.inputs do
        f.input :owner, as: :select, collection: Logger.where(:tested => false)
      end
      f.actions
    end
  end
end

but I only see the button in the HTML produced without the select tag:

<div id="active_admin_content" class="without_sidebar">
  <div id="main_content_wrapper">
    <div id="main_content">
      <form accept-charset="UTF-8" action="/activeadmin/attach_logger" class="formtastic project" method="post" novalidate="novalidate">
        <div style="margin:0;padding:0;display:inline">
          <input name="utf8" type="hidden" value="&#x2713;" />
          <input name="authenticity_token" type="hidden" value="YjpVXb+RYu6xX7IggTQys77bsS98ChuJU02vDZeZR+s=" />
        </div>
        <fieldset class="actions">
          <ol>
            <li class="action input_action " id="project_submit_action">
              <input name="commit" type="submit" value="Submit Project" />
            </li>
          </ol>
        </fieldset>
      </form>
    </div>
  </div>
</div>

when I comment out the f.actions I can see the select tag in the HTML:

<div id="active_admin_content" class="without_sidebar">
  <div id="main_content_wrapper">
    <div id="main_content">
      <form accept-charset="UTF-8" action="/activeadmin/attach_logger" class="formtastic project" method="post" novalidate="novalidate">
        <div style="margin:0;padding:0;display:inline">
          <input name="utf8" type="hidden" value="&#x2713;" />
          <input name="authenticity_token" type="hidden" value="YjpVXb+RYu6xX7IggTQys77bsS98ChuJU02vDZeZR+s=" />
        </div>
          <fieldset class="inputs">
            <ol>
              <li class="select input required" id="project_owner_input">
                <label class="label" for="project_owner">
                  Owner
                  <abbr title="required">
                  *
                  </abbr>
                </label>
                <select id="project_owner" name="project[owner]">
                  <option value=""></option>
                  <option value="6142">#&lt;Logger:0x0000000b528ab8&gt;</option>
                  <option value="6143">#&lt;Logger:0x00000002b023e8&gt;</option>
                  <option value="6146">#&lt;Logger:0x00000002b04c38&gt;</option>
                </select>
              </li>
            </ol>
          </fieldset>
        </form>
      </div>
    </div>
  </div>

how can I get them in the same form?

Was it helpful?

Solution

You'll want to use active_admin_form_for instead of semantic_form_for.

active_admin_form_for :project do |f|
  f.inputs do
    f.input :owner, as: :select, collection: Logger.where(:tested => false)
  end
  f.actions
end

The reason is due to how Arbre buffers content versus Rails' approach to buffering content. Here ActiveAdmin provides a wrapper to help with that issue via its active_admin_form_for form helper.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top