【问题标题】:Embed additional HTML inside of link_to call在 link_to 调用中嵌入额外的 HTML
【发布时间】:2014-08-06 15:30:55
【问题描述】:

如何在 link_to 调用中嵌入额外的 HTML?

这是我想要的结果:

<a href="/exercies/show/1"><i class="icon-show"></i>Show</a>

这是我的link_to电话

<%= link_to "Show", exercise_path(exercise) %>

【问题讨论】:

标签: ruby-on-rails


【解决方案1】:
<%= link_to '<i class="icon-search"></i> Show'.html_safe, exercise_path(exercise), :class => 'btn btn-small' %>

.html_safe 是必需的,因此它不会被转义。

【讨论】:

    【解决方案2】:

    如果你把它包裹在一个do块中会更干净

    <%= link_to exercise_path(exercise) do %> <i class="icon-search"></i> Show <% end %>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多