3

I have an XML view in a rails app, and need to insert in XML from another file for testing purposes.

I want to say "builder, just stuff this string in blindly, because it's already xml", but I can't see to see anything in the docs that does that.

1 Answer 1

6

I knew I'd figure it out right after posting a question. Using target! is the answer

xml.Foo do
  xml.built('build with builder')
  xml.alsobuilt do
    xml.builtinside('built inside')
    xml.target! << my_string_with_xml
  end
end

Achieves the results desired.

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

2 Comments

+1 All the docs say is "Return the target of the builder" :-(
The reason this works is that xml.target! returns the object where the generated XML is being stored - in most cases, this is simply a string.The << my_string_with_xml then appends your string with XML directly to the output, before allowing Builder to continue.

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.