10

I have a code that needs to be split into two lines so it looks nice. However when I try:

link_to "Some Text<br />Here",url_path

it will output the HTML too, even if I use html.html_safe like so:

html = ""
html += link_to "Some Text<br />Here",url_path
html.html_safe

How can I make it so "Here" will appear on a new line?

Paul Sonier
  • 38,903
  • 3
  • 77
  • 117
Travis Pessetto
  • 3,260
  • 4
  • 27
  • 55

2 Answers2

23
link_to "Some Text<br />Here".html_safe, url_path
Jeremy Roman
  • 16,137
  • 1
  • 43
  • 44
19

A trick most Rails developers don't know is that link_to accepts a block:

<%= link_to(url_path) do %>
  Some Text
  <br />
  Here
<% end %>
Mario Uher
  • 12,249
  • 4
  • 42
  • 68