【问题标题】:Rails 6 Active Admin render Arbre partial within Arbre form partialRails 6 Active Admin 在 Arbre 表单中渲染 Arbre 部分
【发布时间】:2022-08-17 10:32:14
【问题描述】:
  • 红宝石 2.7.4
  • 导轨 6.1.3.2
  • 活动管理员 2.9.0
  • Arbre 1.4.0

我无法在主窗体部分 _form.html.arb 内渲染一个小部分 _person_fields.html.arb

我正在使用阿布雷部分中的组件columnscolumn。但它不会呈现构成列的预期 div 元素。如果我不使用部分,并将代码直接放在_form.html.arb 中,它会按预期工作。

如果我在部分内部放置一个断点并在控制台上运行:

columns do
  column do
    \"Here\"
  end
end

它使用div 列输出预期的html。

表单本身可以使用任何一种方式。

我在app/admin/archives/archives.rb 的管理资源
ActiveAdmin.register Archive do
  config.create_another = true

  [...]

  form partial: \"form\"
end
我的表格部分在app/views/admin/archives/_form.html.arb
url = archive.new_record? ? admin_archives_path : admin_archive_path(archive)
active_admin_form_for resource, url: url  do |f|
  [...]
  render \"admin/shared/person_fields\", f: f
  [...]
  f.actions
end
我的部分app/views/admin/shared/_person_fields.html.arb
f.inputs \"Pessoas citadas\" do
  columns do
    column do
      f.inputs \"Testemunhos citados\" do
        f.input :people, collection: Survivor.all, label: false, input_html: { class: \"select2-init\", style: \"width: 100%;\", id: \"archive_survivor_ids\" }
      end
    end
    column do
      f.inputs \"Personalidades citados\" do
        f.input :people, collection: Personality.all, label: false, input_html: { class: \"select2-init\", style: \"width: 100%;\", id: \"archive_personality_ids\" }
      end
    end
    column do
      f.inputs \"Outros citados\" do
        f.input :people, collection: Commoner.all, label: false, input_html: { class: \"select2-init\", style: \"width: 100%;\", id: \"archive_commoner_ids\" }
      end
    end
  end
end
不带部分输出
<fieldset class=\"inputs\">
  <legend><span>Pessoas citadas</span></legend>
  <ol>
    <div class=\"columns\">
      <div class=\"column\" style=\"width: 32%; margin-right: 2%\">
        <fieldset class=\"inputs\">[...]</fieldset>
      </div>
      <div class=\"column\" style=\"width: 32%; margin-right: 2%\">
        <fieldset class=\"inputs\">[...]</fieldset>
      </div>
      <div class=\"column\" style=\"width: 32%\">
        <fieldset class=\"inputs\">[...]</fieldset>
      </div>
      <div style=\"clear: both\"></div>
    </div>
  </ol>
</fieldset>

部分输出
<fieldset class=\"inputs\">
  <legend><span>Pessoas citadas</span></legend>
  <ol>
    <fieldset class=\"inputs\">[...]</fieldset>
    <fieldset class=\"inputs\">[...]</fieldset>
    <fieldset class=\"inputs\">[...]</fieldset>
  </ol>
</fieldset>

  • 我遇到了同样的问题。这是f.inputs 导致更早写入部分内部的缓冲区。您会在 HTML 的末尾看到 columns/column。我还没有找到解决方法。

标签: ruby-on-rails ruby activeadmin arbre


【解决方案1】:

从这个old github issue,我稍微更新了它(使用 arb 和更新的语法):

# app/admin/dashbords.rb:

    section "My Section" do 
      render partial: "stuff", locals: { context: self }
    end

# app/views/dashboard/_stuff.html.arb:

    context.instance_eval do  

      panel "hello" do
         h2 "world"
      end
    end

只要您在本地传递f,它也可以在表单中使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多