How to generate xml tags dynamically from Rails DB using Nokogiri XML Builder

401 views Asked by At

I want to build xml from rails application. I wanted to generate tags from rails application database.

For example: I have a database table called cars and it have variable brand and it has values.

So I want to generate xml like this

<dodge> </dodge>

I tried by doing so

xml.cars.brand do 

end

But I'm getting NoMethodError

1

There are 1 answers

0
Ruby4Rails On BEST ANSWER

Create variable in the controller like this

brand = Car.find(id).brand

and then generate xml like below

xml.tag!(brand) do

end