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
Rails got a helper method out of the box, so you dont have to write your own method.
From the documentation:
simple_format(text, html_options={}, options={})
my_text = "Here is some basic text...\n...with a line break."
simple_format(my_text)
# => "Here is some basic text...\n
...with a line break.
"
more_text = "We want to put a paragraph...\n\n...right there."
simple_format(more_text)
# => "We want to put a paragraph...
\n\n...right there.
"
simple_format("Look ma! A class!", :class => 'description')
# => "Look ma! A class!
"