[英]How to replace \n new line character in string so that <p> tag can show new line
[英]rails render helper to return a p tag with '\n' as new line
我在里面用'\\ n'得到這個字符串,我想顯示一個新行,其中有'\\ n'而不是顯示原始字符串
在fruits.description里面
fruits.description: 'This is an red apple \n It is also very sweet'
我的渲染輔助方法
def get_description(fruits)
if fruits.type == 'apple'
haml_tag 'p', fruits.description, {id: fruits.id}
end
end
我想要顯示字符串,就像這樣
This is an red apple
It is also very sweet
嘗試simple_format
,它將添加<p>
標簽以及將\\n
轉換為<br>
等。
特別:
兩個或多個連續換行符(\\ n \\ n)被視為段落並包含在
<p>
標記中。 一個換行符(\\ n)被視為換行符,並附加<br />
標記。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.