0

This is a little unorthodox, but I don't think it should be difficult.

I have a Active Admin form:

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

When rendered, the last_update_time label does not convert the <br/> into a line break. Similarly, html entity codes such as &copy; (the copyright (c)) aren't converted either.

How can I get html to render in that label?

Stuff I tried that doesn't work:

  • label "foo<br/>bar".html_safe

  • label raw("foo<br/>bar")

  • a block like this (gets an error on label: "wrong number of arguments (given 0, expected 1..3)"):

      label do
        "foo"
        br
        "bar"
      end
    

Anybody know the trick?

Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98

2 Answers2

2

Try next:

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

&copy; must be inside a text_node too like:

text_node "&copy;".html_safe
Esteban CAES
  • 61
  • 1
  • 2
0

Alas Formtastic is not built on Arbre and is somewhat hacked into ActiveAdmin. I would try replacing Formtastic's label here with Arbre's text_node

Piers C
  • 2,880
  • 1
  • 23
  • 29
  • But I actually want a ` – Grant Birchmeier Jul 30 '20 at 14:57