Travis Pessetto
Travis Pessetto

Reputation: 3298

Adding line break to link_to in Rails

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?

Upvotes: 10

Views: 6017

Answers (2)

Mario Uher
Mario Uher

Reputation: 12397

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

Upvotes: 19

Jeremy Roman
Jeremy Roman

Reputation: 16355

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

Upvotes: 23

Related Questions