In my Rails 3 application I use textarea
to let users to write a new message in a forum.
However, when the message is displayed, all newlines look like spac
I believe one of the easiest options is to use css white-space: pre-line;
Other answers also mentioned using white-space, but I think it needs a little more information:
In most cases you should probably choose pre-line
over pre-wrap
. View the difference here.
It's very important to keep in mind about white-space
that you should not do something like this:
<%= your.text %>
It will produce extra spaces and line-breaks in the output. Instead, go with this:
<%= your.text %>
Another way is to wrap your text in tags. And last note on my CSS option is true here as well:
<%= your.text %>
Don't separate your text from tags with spaces or line-breaks.
After googling this matter a little I have a feeling that html-approach is considered less clean than the css one and we should go css-way. However, html-way seems to be more browser-compatible (supports archaic browsers, but who cares):
pre tag
white-space