简体   繁体   中英

How do I display the text with all of the tabs and new lines (\t and \n) in Ruby on Rails?

I have a variable 'messages' of type array and whenever I put it into the terminal it has tabs and new lines but whenever I save messages to a variable and display it on my rails application, it no longer has these. How do I fix this so it shows the new lines and tabs on the rails app.

Code for outputting to the terminal in model (User):

   def runMessages
     messages << stdout.read
     messages << stderr.read
     puts "OUTPUT IS:" + messages[0]
     messages
   end

Code in controller for saving to variable:

   messages = @user.runMessages
   @user.output = messages[0]

Code in views:

    <p> <%= @user.output %> </p>

In the terminal it looks something like this:

    Beginning run ...
    Done.

While on the application it looks like this:

Beginning run...Done.

Use the HTML <pre> tag.

<pre> <%= @user.output %> </pre>

You could also use it in combination with the <code> tag, see this question for the difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM