如何向 erb 中的字符串添加空格?

How can I add a whitespace to a string in erb?

我在 erb 中将 link 显示为字符串:

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

如何在开头添加一个space? 如果我这样做:" " + (@teacher.id + 1).to_s,space 将被忽略,如果我这样做:"&nbsp" + (@teacher.id + 1).to_s 或这样:'&nbsp' + (@teacher.id + 1).to_s,它只会将“ ”解释为五-字符串.

试试这个:

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

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