rails render helper返回带有'\n'的ap标签作为新行

Air*_*219 3 html haml ruby-on-rails

我在里面用'\n'得到这个字符串,我想显示一个新行,其中有'\n'而不是显示原始字符串

在fruits.description里面

fruits.description: 'This is an red apple \n It is also very sweet'
Run Code Online (Sandbox Code Playgroud)

我的渲染辅助方法

def get_description(fruits)
  if fruits.type == 'apple'
    haml_tag 'p', fruits.description, {id: fruits.id}
  end
end
Run Code Online (Sandbox Code Playgroud)

我想要显示字符串,就像这样

This is an red apple
It is also very sweet
Run Code Online (Sandbox Code Playgroud)

mea*_*gar 8

尝试simple_format,这将增加的<p>标签,以及转换\n<br>等.

特别:

两个或多个连续换行符(\n \n)被视为段落并包含在<p>标记中.一个换行符(\n)被视为换行符,并<br />附加一个标记.