capcode01
capcode01

Reputation: 163

Rails xml builder link with custom tag

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)))

Upvotes: 1

Views: 1500

Answers (2)

betromatic
betromatic

Reputation: 69

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

Upvotes: 0

Chris Hall
Chris Hall

Reputation: 905

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?

Upvotes: 2

Related Questions