【问题标题】:Rails Active Admin: Why isn't my custom form rendering any inputs?Rails Active Admin:为什么我的自定义表单没有呈现任何输入?
【发布时间】:2012-09-02 18:50:01
【问题描述】:

Rails 3.1.1
活动管理员 0.4.4
格式 2.1.1

这是我的Agency 模型的活动管理控制器。

ActiveAdmin.register Agency do
  form do |f|
    f.input :name
    f.input :contact_email, :label=>"Email invoices to"
    f.input :api_key, :hint=>"Create a key by following <a href=\"#\" target=\"_blank\">these instructions</a>".html_safe
    f.actions
  end
end

表单应该呈现三个输入,然后是提交按钮,但我得到的只是:

为了清楚起见,HTML 没有显示缺少输入的迹象:

<form accept-charset="UTF-8" action="/admin/agencies" class="formtastic agency" id="agency_new" method="post" novalidate="novalidate" name="agency_new">
  <div style="margin:0;padding:0;display:inline">
    <input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="...">
  </div>
  <fieldset class="actions">
    <ol>
      <li class="action input_action" id="agency_submit_action">
        <input name="commit" type="submit" value="Create Agency">
      </li>
    </ol>
  </fieldset>
</form>

我也尝试使用字段集,但输出相同(错误):

ActiveAdmin.register Agency do
  form do |f|
    f.inputs "New Agency" do 
      f.input :name
      f.input :contact_email, :label=>"Email invoices to"
      f.input :api_key, :hint=>"Create a key by following <a href=\"#\" target=\"_blank\">these instructions</a>".html_safe
    end
    f.actions
  end
end

更新:我发现注释掉 f.actions 行会变得非常适合实际打印输入,但现在只是没有按钮。

ActiveAdmin.register Agency do
  form do |f|
    f.inputs "New Agecny" do 
      f.input :name
      f.input :contact_email, :label=>"Email invoices to"
      f.input :api_key, :hint=>"Create a key by following <a href=\"#\" target=\"_blank\">these instructions</a>".html_safe
    end

    #f.actions
  end
end

有输入但没有按钮的表单:

【问题讨论】:

    标签: ruby-on-rails-3 activeadmin formtastic


    【解决方案1】:

    应该使用f.buttons,而不是f.actions

    f.buttons,打印按钮。 f.actions 需要一个用于格式化按钮的块,类似于f.inputs

    【讨论】:

      【解决方案2】:

      你是正确的:将你的输入包装在一个 f.inputs 块中。

      取消注释块外的“f.actions”行。

      你应该准备好了。

      【讨论】:

        【解决方案3】:

        尝试使用这个:f.input :type => :submit 。这对我有用

        form do |f| 
          f.input :starts_at
          f.input :ends_at
          f.input :type => :submit
        end
        

        【讨论】:

          【解决方案4】:

          试试这个:f.buttons :submit

          我还认为按钮/操作的块在某个时候在活动管理员版本中发生了一些变化,因此您可能会被旧教程等绊倒。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2020-12-27
            • 1970-01-01
            • 2021-08-16
            • 1970-01-01
            • 2011-08-07
            • 1970-01-01
            • 2019-06-20
            相关资源
            最近更新 更多