我有以下href
代码
<a class="btn btn-sm btn-success" href="#"><i class="fa fa-check"></i></a>
Rails代码
<%= link_to "<i class=\"fa fa-check\"></i>", event_expenses_accept_path(:id => event_expense.id), :method => :post, :class => "accept btn btn-sm btn-success", remote: true %>
试过
<%= link_to (raw("<i class=\"fa fa-check\"></i>"), event_expenses_accept_path(:id => event_expense.id), :method => :post, :class => "accept btn btn-sm btn-success", remote: true) %>
答案 0 :(得分:2)
您可以使用blocks:
<%= link_to("#", class: "add_fields btn btn-success") do %>
<i class="fa fa-check"></i>
<% end %>
将生成:
<a class="btn btn-sm btn-success" href="#">
<i class="fa fa-check"></i>
</a>
此外,这也有效:
<%= link_to (raw("<i class=\"fa fa-check\"></i>")), event_expenses_accept_path(:id => event_expense.id), :method => :post, :class => "accept btn btn-sm btn-success", remote: true %>
生成:
<a class="accept btn btn-sm btn-success" data-method="post" data-remote="true" href="your_path" rel="nofollow">
<i class="fa fa-check"></i>
</a>
答案 1 :(得分:1)
将HTML作为块传递,试试这个
<%= link_to event_expenses_accept_path(:id => event_expense.id), :method => :post, :class => "accept btn btn-sm btn-success", remote: true do %>
<i class="fa fa-check"></i>
<% end %>
答案 2 :(得分:1)
这也有效:
<%= link_to(content_tag('i', '', class: 'fa fa-check'), "#", class: "btn btn-sm btn-success") %>