In the controller, I have an variable @xml_string = "<tag> hello \n world </tag>". Now I want to show the content of @xml_string. In erb file I wrote <%= @xml_string %>, but this can only display hello world, the xml tag <tag> </tag> was missed and \n was ignored.
Aslo , <% render :text => @xml_string , :content_type = 'application/xml' %> would not show any thing at all.
what is the correct way to achieve this? Thanks.
HTML ignores new line characters and white spaces unless you wrap the content into a tag that is whitespace-aware.
Otherwise, replace the “\n” with a line break. In this case you need to manually escape the HTML string.