简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM