Reputation: 377
I have a rails app that allows users to type in text. I wanted to know how do I make that text formatted?
For example when a user makes a new paragraph in the text input field, I want those gaps to show when I render the text to be displayed but, at the moment it is just a big chunk of text with no spaces.
Any suggestions?
Thanks in advance
Upvotes: 2
Views: 3772
Reputation: 2385
Use simple_format here doc. m sure it will work,
here how i use it in my project;
= simple_format my_text
where
my_text = "foo bar
Testing helloworold foo bar
Testing helloworld foo bar
Testing helloworld foo bar
Testing helloworld foo bar
Testing helloworld foo bar
"
This will get displayed with enters you have given in the text and will render all the spaces also.
Upvotes: 7
Reputation: 3371
When a user use <Enter>
character in a text input (or text area), it will be correctly displayed into it.
Rails doen't make particular traitment with this character. Then, when you render it, you create some HTML like <%= my_text %>
. But <Enter>
characters are not rendered in HTML.
You can use simple_format to do that: it replace all the \n
(enter caracters) with some <br/>
.
http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format
Upvotes: 7