【问题标题】:How to show link html code with html tags inside it?如何在其中显示带有 html 标签的链接 html 代码?
【发布时间】:2012-01-22 12:21:09
【问题描述】:

假设我有这个:

link_to "Profile", profile_path(@profile)

# => <a href="/profiles/1">Profile</a>

但如果我只需要像 &lt;a href="/profiles/1"&gt;&lt;h1&gt;Title&lt;/h1&gt;&lt;p&gt;some text&lt;/p&gt;&lt;/a&gt; 这样的 href 链接?

是否有任何 Rails 方法可以做到这一点?

编辑:解决方案是这样的块使用:

<%= link_to(@profile) do %>
<strong><%= @profile.name %></strong> -- <span>Check it out!</span>
<% end %>
# => <a href="/profiles/1">
   <strong>David</strong> -- <span>Check it out!</span>
</a>

【问题讨论】:

  • link_to "", profile_path(@profile) 也许?
  • 抱歉,我必须编辑才能准确询问我要查找的内容..
  • 刚刚在有关使用块的文档中找到。谢谢!

标签: ruby-on-rails-3 view-helpers


【解决方案1】:

这是解决方案:

<%= link_to(@profile) do %>
<strong><%= @profile.name %></strong> -- <span>Check it out!</span>
<% end %>
# => <a href="/profiles/1">
<strong>David</strong> -- <span>Check it out!</span>
</a>

希望对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 2019-04-11
    • 2023-01-24
    • 2011-12-13
    • 1970-01-01
    相关资源
    最近更新 更多