如何在erb中为字符串添加空格?

时间:2015-02-11 21:57:36

标签: html ruby erb

我在erb中显示一个字符串链接:

<%= link_to (@teacher.id + 1).to_s, "#" %>

如何在开头添加一个空格? 如果我执行此操作:" " + (@teacher.id + 1).to_s,则会忽略该空格,如果我执行此操作:"&nbsp" + (@teacher.id + 1).to_s或此:'&nbsp' + (@teacher.id + 1).to_s,则只会将“&amp; nbsp”解释为五个字符的字符串

1 个答案:

答案 0 :(得分:6)

试试这个:

<%= link_to "&nbsp;#{@teacher.id + 1}".html_safe, "#" %>

参考:http://apidock.com/rails/String/html_safe