6

I want to have two lines in my alert box

Right now I have the following:

<%= link_to 'back', 'history.back()', :confirm => 'Are you sure? This is my second line' %>

I have tried adding '\n' but it is not working, it just writes \n between my text. What should I do?

Thank you in advance

marimaf
  • 5,382
  • 3
  • 50
  • 68

3 Answers3

13

I think the single quotes around your confirm text are causing the \n to be interpreted literally. Try this:

<%= link_to 'back', 'history.back()', :confirm => "Are you sure? \n This is my second line" %>
Oben Sonne
  • 9,893
  • 2
  • 40
  • 61
James
  • 158
  • 4
3

If you want a multi-line confirm/alert statement, you will need to use double quote. Single quote will not convert your new line feed \n

This would work: :confirm => "You are about to \n DELETE all tracking information.\nAre you sure?"

Hope this helps ;)

Galuga
  • 531
  • 2
  • 6
1

New line in JavaScript alert box You need to stop rails from escaping the new line in the generated HTML form. Can you try <%= link_to 'back', 'history.back()', :confirm => raw 'Are you sure? \n This is my second line' %>

Community
  • 1
  • 1
Devin M
  • 9,636
  • 2
  • 33
  • 46