Kumaro Kumaro - 1 year ago 41
Ruby Question

Rails String in View with whitespaces

I'm trying to show a string with xml content (correct with whitespaces etc.) in a rails view.

My Controller action read a xml file and put this content into a string.
For example

@xml_content = "

Then I get this string from my controller and want to show this xml content in a view.

<%= @xml_content %>

But when I print this string in the view all whitespaces get lost and I get something like this:


Printing the same string in the console with "puts @xml_content" create the correct output.

What can I do to show this xml content with all whitespaces in the view?


@file = File.open(@xml_device_description.get_file_path)

@xml_content = Nokogiri::XML @file


To conserve whitespaces of your content, you can wrap it in a pre tag.

 <%= @xml_content %>