George
George

Reputation: 643

Ruby on Rails converts new line \n to \\n

I try save

desc += 'SUBJECT: '
desc += '\n'
desc += 'MESSAGE: '
Teme.desc = desc
Teme.save

but in the Database I have

> Teme.find 190

... desc: "SUBJECT: \\nMESSAGE: 

Then my textarea show \n instead new line

How safely store new line symbol in database?

Upvotes: 0

Views: 1360

Answers (1)

gabrielhilal
gabrielhilal

Reputation: 10769

You should use double quotes with special characters:

desc += 'SUBJECT: '
desc += "\n"
desc += 'MESSAGE: '
Teme.desc = desc
Teme.save

raw desc or desc.html_safe will make the new line

> Teme.find 190

... desc: "SUBJECT: \nMESSAGE:

Upvotes: 7

Related Questions