1

I am creating a data.xml.builder file that I will feed into javascript library to create a table.

A short excerpt is the following

xml.tag!("row",{"id" => item.id}) do
    xml.tag!("cell", item.name)
end

I would like the item.name to also be a link to the item_path in the table.

I know that I can use

xml.a(item.name, 'href' => item_path(item))

in order to create a link. However, I need the custom tag of "cell" in order for the javascript library to pick it up into the proper spot in the table.

Therefore, what I am looking to do is combine these two into something that looks like this. But i know this doesn't work.

xml.tag!("cell", xml.a(item.name, 'href' => item_path(item)))

2 Answers 2

2

You should be able to just do further nesting.

xml.tag!("row",{"id" => item.id}) do
    xml.tag!("cell") do
        xml.a(item.name, 'href' => item_path(item))
    end
end

Which would result in output like the following:

<row id="5">
    <cell>
        <a href="/item/5">Foo</a>
    </cell>
</row>

Is that not what you were intending?

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. I had found another work around. But this is far more elegant.
0

it's possible to display image in xml file?

my code:

!!! XML
%products
  - @products.each do |product|
    %product
    %image= image_tag product.image_url
    %name= product.name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.