Reputation: 826
<%= f.text_area :comment, placeholder: "Comment on your track or" + \n + "share your favorite lyrics" %>
How can I get the placebolder to line break like
Solution was just to add white space so the next line wraps:
placeholder: "Comment on your track or share your favorite lyrics" %>
Pretty ugly but least complicated
Upvotes: 9
Views: 26586
Reputation: 33752
In Ruby, in general "\n"
is the new line character.
e.g.:
puts "first line\nsecond line"
=>
first line
second line
However, in your case:
you seem to try to use the newline character in an .erb
expression <%= ... %>
That does not work, because that will only format the newline in the raw HTML souce, but in the formatted HTML you will not see the newline! :-)
To see the newline in the formatted HTML, you need to do something like this:
<br />
in the string instead of the "\n"
-- <br \>
is the HTML newline symbolUpvotes: 6
Reputation: 10218
The newline character \n
should be included between the double, however HTML does not allow for line feed, but Thomas Hunter suggested an hack which consists in using a bunch of white spaces, like so:
<%= f.text_area :comment, placeholder: "Comment on your track or share your favorite lyrics" %>
You can also opt to use the title
attribute instead.
Upvotes: 7
Reputation: 6971
You're creating HTML code. HTML does not care about whitespace in the actual code. What you need is a break in the HTML itself. However, it seems per this other question Can you have multiline HTML5 placeholder text in a <textarea>? that HTML does not allow line breaks in the placeholder
field.
Upvotes: 1