【问题标题】:In Active Admin / Arbre form, how I can put HTML (specifically a line break) in a label?在 Active Admin / Arbre 表单中,如何将 HTML(特别是换行符)放入标签中?
【发布时间】:2020-07-28 04:05:22
【问题描述】:

这有点不正统,但我认为应该不难。

我有一个有效的管理员表单:

form do |f|
  f.semantic_errors(*f.object.errors.keys)
  f.inputs do
    f.input :email
    f.input :name

    # read-only field that still matches formatting of form
    li do
      label "Last Update Time<br/>(except password changes)"
      div f.object.last_update_time
    end
  end
  f.actions
end

渲染时,last_update_time 标签不会将&lt;br/&gt; 转换为换行符。同样,&amp;copy;(版权(c))等html实体代码也不会被转换。

如何让 html 在该标签中呈现?

我试过的东西不起作用:

  • label "foo&lt;br/&gt;bar".html_safe

  • label raw("foo&lt;br/&gt;bar")

  • 这样的块(在label 上出现错误:“参数数量错误(给定 0,预期为 1..3)”):

      label do
        "foo"
        br
        "bar"
      end
    

有人知道诀窍吗?

【问题讨论】:

    标签: activeadmin formtastic arbre


    【解决方案1】:

    尝试下一个:

    li do
      text_node "<label>Last Update Time<br/>(except password changes)"</label>".html_safe
      div f.object.last_update_time 
    end
    

    &amp;copy; 也必须在 text_node 内,例如:

    text_node "&copy;".html_safe
    

    【讨论】:

    • 效果很好!好吧,无论如何,这是一个完美的解决方法。谢谢。
    【解决方案2】:

    Alas Formtastic 不是基于 Arbre 构建的,它在某种程度上被入侵到了 ActiveAdmin 中。我会尝试用 Arbre 的 text_node 替换 Formtastic 的 label

    【讨论】:

    • 但我实际上想要一个&lt;label&gt; 标签,所以它会有AA 标签样式。 (我可以使用其他东西,然后调整我的 css 以复制 AA 标签样式,但这正是我要避免的。)
    猜你喜欢
    • 2022-08-17
    • 2013-04-07
    • 2017-02-21
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2011-11-01
    • 2022-11-14
    • 2013-03-17
    相关资源
    最近更新 更多