ruby-on-railsrubyxmlnokogirixml-builder

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


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


Solution

  • Create variable in the controller like this

    brand = Car.find(id).brand
    

    and then generate xml like below

    xml.tag!(brand) do
    
    end