Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have a div with multiple children in ActiveAdmin/Arbre

I have this code:

div class: item.ui_type do
  link_to image_tag(item.image.image_public_url), item.target)
  link_to item.label, item.target
end

Basically, I want a div with 2 links inside. However, only the last element is getting rendered, presumably because what gets rendered inside the body is the return value of the block.

I know I can declare those as an array and join them, but then I need to call html_safe. I'm trying to find a way to do this when you actually don't trust the input that you're receiving.

This seems like it should be an extremely simple thing to do, but I can't find it anywhere.

Any pointers?

like image 233
Daniel Magliola Avatar asked Mar 03 '15 10:03

Daniel Magliola


2 Answers

I suspect the reason atomdev's example works and Daniel's does not is that link_to is a Rails tag helper and a is an Arbre tag, see this similar issue. Try wrapping link_to with text_node, div or span. It might be worth opening an Arbre GitHub issue for this.

like image 105
Piers C Avatar answered Nov 10 '22 21:11

Piers C


Here's what I did to add two links inside the div

div(:class => "some_class") do
  [
    link_to("Link1", link1_path),
    link_to("Link2", link2_path)
  ].join.html_safe
end

Behind it does is first, create the link tag in strings inside an array, second, you join these strings and make it html_safe so div can accept it.

like image 23
vpibano Avatar answered Nov 10 '22 23:11

vpibano