简体   繁体   English

在Rails中为link_to添加换行符

[英]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.html_safe:

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 : 大多数Rails开发人员不知道的一个技巧是link_to接受一个块

<%= link_to(url_path) do %>
  Some Text
  <br />
  Here
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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