在Rails数据库列中保留空格/缩进

时间:2015-10-10 03:34:06

标签: ruby-on-rails database whitespace indentation strip

我有一个存储在数据库中的伪代码文本块,它们逐行打印并以HTML格式显示。

在数据库的文本列中输入伪代码:

while (counter <= 10) {
  printf("Enter grade: ");
  scanf("%d", &grade);
  total = total + grade;
  counter = counter + 1;
} /* end while */

控制器:

def index
    @code = Code.first // just a filler for the time being
end

指数:

- @code.cont.each_line do |line|
    - i += 1
    .line
        %span= i
        %li.line= line
- i = 0

在某些方面,Ruby会自动删除任何空格,只留下文本。我想知道如何保留这个以便

此:

while (counter <= 10) {
  printf("Enter grade: ");
  scanf("%d", &grade);
  total = total + grade;
  counter = counter + 1;
} /* end while */

不能这样出来:

while (counter <= 
printf("Enter grade: ");
scanf("%d", &grade);
total = total + grade;
counter = counter + 1;
} /* end while */

0 个答案:

没有答案