semantic_form_for的提交按钮取消输入字段

时间:2014-02-13 16:37:40

标签: html ruby-on-rails-4 activeadmin formtastic

我正在尝试使用以下代码在新页面中使用active-admin创建表单:

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

但我只看到HTML中没有select标签的按钮:

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

当我注释掉f.actions时,我可以看到HTML中的select标记:

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

如何以相同的形式获取它们?

1 个答案:

答案 0 :(得分:5)

您需要使用active_admin_form_for代替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

原因在于Arbre如何缓冲内容与Rails缓冲内容的方法。在这里,ActiveAdmin通过其active_admin_form_for表单帮助程序提供了一个帮助解决该问题的包装器。