0

I have a simple form, where a user can write some text and this text will be send to his email. This process works fine, but I have a problem with the text, that user wrote - in the email is displayed following:

["sadgsdah\r\nsdh\r\ndsf\r\nh\r\nfdhdfhdfh\r\n\r\n\r\n\r\nfdh\r\ndf\r\njh"]

why there are the brackets and the \n and \r chars?

Before than I give the variable with the content into the email template, I tried to do following:

mess_body = params[:contact][:message].to_s.html_safe

But unfortunately this didn't help me... what I am doing wrong?

0

2 Answers 2

1

To convert newlines to look right in html, use simple_format to convert the text.

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

Comments

0

First of all

mess_body = params[:contact][:message]

returns a array, not a single thing. That is why you get the [" and "] around the output. you could get the first element like this:

mess_body = params[:contact][:message][0]  

Furthermore \n\r are line endings of a text box. Assuming that the e-mail you're sending is HTML the \n\r should be replaced by <br> in the String

5 Comments

yes, I totally forgot for that array instead of string. But still have the problem about \n\r - they're just replaced by the white space, not by the new line - this is how I see that in the mailbox. But when I take a look at the log of the project, there are correctly displayed new line tags...
If the text is going into an html message, newlines are converted are just spaces visually - to make html force a newline, you need a <BR> tag
@DGM you mean I have to manually convert \n\r chars to <br />?
Yes That is what you should do
yes, but don't reinvent it, use the rails helper I posted in another answer.

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.