2

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

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

7

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.