Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

line break for a string placeholder in ruby

<%= 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

like image 200
Jaqx Avatar asked Apr 29 '13 22:04

Jaqx


2 Answers

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.

like image 190
Luís Ramalho Avatar answered Oct 05 '22 08:10

Luís Ramalho


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:

  • either put the two strings in separate DIVs or SPANs
  • or put a <br /> in the string instead of the "\n" -- <br \> is the HTML newline symbol
like image 31
Tilo Avatar answered Oct 05 '22 08:10

Tilo