In Active Admin / Arbre form, how I can put HTML (specifically a line break) in a label?

1.5k views Asked by At

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?

2

There are 2 answers

1
Esteban CAES On BEST ANSWER

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
1
Piers C On

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