0

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

4
  • Please show the full error. What is cars? What is cars.brand? Is there a car without a brand? And what is xml? Commented Feb 19, 2019 at 16:04
  • Cars is the table name, Brand is the column name and I wanted to generate this xml using xml nokogiri builder and I've edited my question, Sorry for the inconvenience. Commented Feb 19, 2019 at 16:20
  • You have not provided much to go on and if your comment is accurate than your answer is not. Cars.brand will call the brand method on the class instance Cars but in your comment you stated that brand is an attribute method of an instance of Car not the class itself. Therefor the answer posted is likely to raise NoMethodError for Cars, which btw is not the correct model name under rails convention as model names are singular Commented Feb 19, 2019 at 20:55
  • Ya that was the typo, Thanks for correcting me, Edited answer. Commented Feb 20, 2019 at 16:45

1 Answer 1

1

Create variable in the controller like this

brand = Car.find(id).brand

and then generate xml like below

xml.tag!(brand) do

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

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.