Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Dave Faliskie
Dave Faliskie
17,793 Points

Why cant I display enters with a textbox input.

I am using ruby on rails.

I have a forum which has a text box. Everything works fine the user can enter text and it saves it to the database. however if the user uses the enter key to go to the next line it is not displayed when the text is printed on another page.

for example if I type in the text box:

Hello,
This is text.

it is displayed like this when I call it back.

Hello, This is text.

I am storing the text in a table called comments and in a row called remarks, I am using the following code to call the text.

<%= comments.remark %>

does anyone know how I can make the user inputed "enters" to display when the text is called bak?

Thanks Dave

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Notice that it works the same on Treehouse forums. I had to use my moderator powers to edit your question properly. I think you have to use two enters to have any kind of reaction (i.e. there will be one empty line).

Dave Faliskie
Dave Faliskie
17,793 Points

On my site, even if I use 2 enters everything still gets displayed on one line. I guess it is possible because this forum allows it.

On my site this line would be right after the last sentence.

Is this a quick fix?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, so I don't have any fix for this right now...

Dave Faliskie
Dave Faliskie
17,793 Points

Thanks the link led me to the answer, for anyone else I used

 <%= safe_join(table.content.split("\r\n"), "<br />".html_safe) %>

where table.content is what is being rendered.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I'm glad this worked! I will surely use this in my next hobby project ;)