Line break for ruby โโstring placeholder
<%= f.text_area :comment, placeholder: "Comment on your track or" + \n + "share your favorite lyrics" %> How can I make placebolder break a line like
The solution was only to add a space so that the next line wraps around:
placeholder: "Comment on your track or share your favorite lyrics" %> Pretty ugly but least complicated
A newline character \n must be included between doubles, however HTML does not allow the use of a line feed, but Thomas Hunter suggested hacking , which consists in using a bunch of white spaces, for example:
<%= f.text_area :comment, placeholder: "Comment on your track or share your favorite lyrics" %> You can also use the title attribute.
In Ruby, generally speaking, "\n" is the newline character.
eg:.
puts "first line\nsecond line" => first line second line However, in your case:
it seems you are trying to use a newline in the .erb expression <%= ... %>
This does not work, because it will only format a new line in a raw HTML sum , but in formatted HTML you will not see a new line! :-)
To see a new line in formatted HTML , you need to do something like this:
- either put two lines in separate div or span
- or put in the string
<br />instead of"\n"-<br \>HTML newline character
You are creating HTML code. HTML doesn't care about whitespace in the actual code. You need a break in the HTML itself. However, it seems like this other question. Can you have multi-line HTML5 placeholder text in <textarea>? that HTML does not allow line breaks in the placeholder field.