0

这有点傻。我将 Rails 用于我的网络应用程序。它使用以下语句从数据库中获取数据

<div class="show-content"> <%= @page.content %> </div>

相同的示例 html 输出。

<div class="show-content">
Migrations are a convenient way for you to alter your database in a structured and organized manner.

Active Record tracks which migrations have already been run so all you have to do is update your source and run rake db:migrate. 

Migrations also allow you to describe these transformations using Ruby. 
</div>

如您所见,它们由 3 个段落组成。但是当它们被显示时,换行符(空格)被剥离,这不是我想要的。我应该创建一个助手还是有一个内置函数来做到这一点?

4

2 回答 2

5

尝试使用simple_format()which 使用 HTML 规则转换输入。TextHelper#simple_format 文档

于 2013-06-07T17:11:53.850 回答
1

你可能不得不做两件事之一。

处理服务器上的内容,以便每条“行”都包含在<p>标签中并根据需要设置它们的样式

或者

将您的模板更改为以下内容:

<div class='show-content'>
    <pre><%= @page.content %></pre>
</div>
于 2013-06-07T17:11:22.247 回答