我在 erb 中将链接显示为字符串:
<%= link_to (@teacher.id + 1).to_s, "#" %>
如何在开头添加一个空格?
如果我这样做:""+ (@teacher.id + 1).to_s
,空格将被忽略,如果我这样做:" "+ (@teacher.id + 1).to_s
或此:' ' + (@teacher.id + 1).to_s
,它只是将“ ”解释为五个字符的字符串。
最佳答案
试试这个:
<%= link_to " #{@teacher.id + 1}".html_safe, "#" %>
关于html - 如何向 erb 中的字符串添加空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28465329/