rails - 使用段落返回输出用户输入? [英] rails - outputting user input with Paragraph Returns?
本文介绍了rails - 使用段落返回输出用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 textarea 输入,允许用户输入多个段落,这意味着用户可以输出一个新行.
I have a textarea input that allows users to input in more than on paragraph, meaning the user can output a new line.
问题是当我从数据库中输出时,它全部缩小为一行?
Problem is when I output that from the database it's all shrunk into one line?
如何将新行变成 HTML 友好的新行,使其看起来像用户输入文本的方式?
How do I make that new line into an HTML friendly new line so it looks the way the user inputted the text?
谢谢
推荐答案
使用 simple_format 帮手.它用
或
Use the simple_format helper. It's replace all \n by <br />
or <p>
来自 API 的示例:
Examples from API :
my_text = "Here is some basic text...\n...with a line break."
simple_format(my_text)
# => "<p>Here is some basic text...\n<br />...with a line break.</p>"
more_text = "We want to put a paragraph...\n\n...right there."
simple_format(more_text)
# => "<p>We want to put a paragraph...</p>\n\n<p>...right there.</p>"
simple_format("Look ma! A class!", :class => 'description')
# => "<p class='description'>Look ma! A class!</p>"
这篇关于rails - 使用段落返回输出用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文