Jeff Caros
Jeff Caros

Reputation: 979

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

I'm displaying a link as a string in erb:

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

How can I add one space at the beginning? If I do this: " " + (@teacher.id + 1).to_s, the space is ignored, and if I do this: "&nbsp" + (@teacher.id + 1).to_s or this: '&nbsp' + (@teacher.id + 1).to_s, it just interprets "&nbsp" as a five-character string.

Upvotes: 2

Views: 1878

Answers (1)

dgilperez
dgilperez

Reputation: 10796

Try this:

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

Reference: http://apidock.com/rails/String/html_safe

Upvotes: 8

Related Questions