Rya*_*yan 68 ruby-on-rails link-to
在使用link_to方法生成的链接主体中获取嵌入式HTML的最佳方法是什么?
我基本上想要以下内容:
<a href="##">This is a <strong>link</strong></a>
Run Code Online (Sandbox Code Playgroud)
我一直试图按照Rails和<span>标签的建议来解决这个问题,但没有运气.我的代码如下所示:
def picture_filter
#...Some other code up here
text = "Show items with " + content_tag(:strong, 'pictures')
link_to text, {:pics => true}, :class => 'highlight'
end
Run Code Online (Sandbox Code Playgroud)
#...
<%=raw picture_filter %>
#...
Run Code Online (Sandbox Code Playgroud)
Val*_*dis 111
试试这种方式
<%= link_to(raw("a <strong>strong</strong> link"),{:pics => true},{ :class => 'highlight'}) %>
Run Code Online (Sandbox Code Playgroud)
mar*_*ark 53
= link_to "http://www.example.com" do
<strong>strong</strong>
Run Code Online (Sandbox Code Playgroud)
Gor*_*Ape 27
截至2016年,我更喜欢这种方法.
<%= link_to url: my_path do %>
This is a <strong>ape</strong>
<% end %>
Run Code Online (Sandbox Code Playgroud)
Sye*_*yed 16
您可以使用 html_safe
<%= link_to ("<i class='someIcon'></i> Link").html_safe %>
Run Code Online (Sandbox Code Playgroud)