Reputation: 3
I'm running into a problem that I can't seem to be able to decipher.
I'm trying to put text into a textarea in a Rails application. I have a variable with the text in it, which is a multi-line string made from reading the contents of a file. This is the string by the end of the reading of the file. However, the string ends up being put in the text area looking like this.
My guess is that it's due to how the textarea parses the new line character. Replacing all of them with <br>
or <br />
renders the tags as plain text. It sounds like there's a simple solution, but I'm not sure how to fix it.
EDIT: Per request, here is the code with the textarea. It's written in HAML, so apologies for that, I couldn't seen to find a HAML to HTML converter that worked (or maybe I'm bad at googling things).
%textarea{:name => "user_css", :width => "90%", :rows => "30", :style => "font-family:Courier; font-size:12; white-space:pre-wrap"}
= css_contents
Upvotes: 0
Views: 1788
Reputation: 6894
A few things you could try
1. Use HAML's :preserve
or find_and_preserve
helper
%textarea{:name => "user_css", :width => "90%", :rows => "30", :style => "font-family:Courier; font-size:12; white-space:pre-wrap"}
:preserve
= css_contents
2. Use HAML's tilde (~)
%textarea{:name => "user_css", :width => "90%", :rows => "30", :style => "font-family:Courier; font-size:12; white-space:pre-wrap"}
~ css_contents
3. Write it in the same line
%textarea{..}= "#{css_contents}"
Upvotes: 1